diff --git a/components/fpspreadsheet/examples/excel2demo/excel2read.lpi b/components/fpspreadsheet/examples/excel2demo/excel2read.lpi index 607bca344..f3b13bc41 100644 --- a/components/fpspreadsheet/examples/excel2demo/excel2read.lpi +++ b/components/fpspreadsheet/examples/excel2demo/excel2read.lpi @@ -10,7 +10,7 @@ - <ActiveEditorIndexAtStart Value="3"/> + <ActiveEditorIndexAtStart Value="0"/> </General> <VersionInfo> <ProjectVersion Value=""/> @@ -26,7 +26,7 @@ <RunParams> <local> <FormatVersion Value="1"/> - <LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/> + <LaunchingApplication PathPlusParams="\usr\X11R6\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/> </local> </RunParams> <RequiredPackages Count="1"> @@ -39,8 +39,8 @@ <Filename Value="excel2read.lpr"/> <IsPartOfProject Value="True"/> <UnitName Value="excel2read"/> - <CursorPos X="6" Y="23"/> - <TopLine Value="12"/> + <CursorPos X="1" Y="42"/> + <TopLine Value="24"/> <EditorIndex Value="0"/> <UsageCount Value="309"/> <Loaded Value="True"/> @@ -69,7 +69,7 @@ <Unit4> <Filename Value="..\..\xlsbiff5.pas"/> <UnitName Value="xlsbiff5"/> - <CursorPos X="37" Y="934"/> + <CursorPos X="20" Y="938"/> <TopLine Value="918"/> <EditorIndex Value="3"/> <UsageCount Value="140"/> diff --git a/components/fpspreadsheet/examples/excel2demo/excel2read.lpr b/components/fpspreadsheet/examples/excel2demo/excel2read.lpr index 21f3f6d5e..22d579dce 100644 --- a/components/fpspreadsheet/examples/excel2demo/excel2read.lpr +++ b/components/fpspreadsheet/examples/excel2demo/excel2read.lpr @@ -40,7 +40,8 @@ begin begin CurCell := MyWorkSheet.GetCellByIndex(i); WriteLn('Row: ', CurCell^.Row, ' Col: ', CurCell^.Col, ' Value: ', - MyWorkSheet.ReadAsAnsiText(CurCell^.Row, CurCell^.Col)); + UTF8ToAnsi(MyWorkSheet.ReadAsUTF8Text(CurCell^.Row, CurCell^.Col)) + ); end; // Finalization diff --git a/components/fpspreadsheet/examples/excel2demo/excel2write.lpi b/components/fpspreadsheet/examples/excel2demo/excel2write.lpi index 144c4522b..52bac16cb 100644 --- a/components/fpspreadsheet/examples/excel2demo/excel2write.lpi +++ b/components/fpspreadsheet/examples/excel2demo/excel2write.lpi @@ -26,7 +26,7 @@ <RunParams> <local> <FormatVersion Value="1"/> - <LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/> + <LaunchingApplication PathPlusParams="\usr\X11R6\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/> </local> </RunParams> <RequiredPackages Count="1"> @@ -39,8 +39,8 @@ <Filename Value="excel2write.lpr"/> <IsPartOfProject Value="True"/> <UnitName Value="excel2write"/> - <CursorPos X="30" Y="37"/> - <TopLine Value="19"/> + <CursorPos X="24" Y="37"/> + <TopLine Value="18"/> <EditorIndex Value="0"/> <UsageCount Value="309"/> <Loaded Value="True"/> @@ -130,7 +130,7 @@ <UsageCount Value="67"/> </Unit11> </Units> - <JumpHistory Count="26" HistoryIndex="25"> + <JumpHistory Count="27" HistoryIndex="26"> <Position1> <Filename Value="..\..\fpolestorage.pas"/> <Caret Line="40" Column="5" TopLine="31"/> @@ -235,6 +235,10 @@ <Filename Value="excel2write.lpr"/> <Caret Line="30" Column="21" TopLine="19"/> </Position26> + <Position27> + <Filename Value="excel2write.lpr"/> + <Caret Line="37" Column="30" TopLine="18"/> + </Position27> </JumpHistory> </ProjectOptions> <CompilerOptions> diff --git a/components/fpspreadsheet/examples/excel2demo/excel2write.lpr b/components/fpspreadsheet/examples/excel2demo/excel2write.lpr index fe38d3024..931e786b3 100644 --- a/components/fpspreadsheet/examples/excel2demo/excel2write.lpr +++ b/components/fpspreadsheet/examples/excel2demo/excel2write.lpr @@ -31,10 +31,10 @@ begin MyWorksheet.WriteNumber(0, 3, 4.0); // Write some string cells - MyWorksheet.WriteAnsiText(1, 0, 'First'); - MyWorksheet.WriteAnsiText(1, 1, 'Second'); - MyWorksheet.WriteAnsiText(1, 2, 'Third'); - MyWorksheet.WriteAnsiText(1, 3, 'Fourth'); + MyWorksheet.WriteUTF8Text(1, 0, 'First'); + MyWorksheet.WriteUTF8Text(1, 1, 'Second'); + MyWorksheet.WriteUTF8Text(1, 2, 'Third'); + MyWorksheet.WriteUTF8Text(1, 3, 'Fourth'); // Save the spreadsheet to a file MyWorkbook.WriteToFile(MyDir + 'test' + STR_EXCEL_EXTENSION, sfExcel2); diff --git a/components/fpspreadsheet/examples/excel5demo/excel5read.lpi b/components/fpspreadsheet/examples/excel5demo/excel5read.lpi index fad98ee92..511f850a4 100644 --- a/components/fpspreadsheet/examples/excel5demo/excel5read.lpi +++ b/components/fpspreadsheet/examples/excel5demo/excel5read.lpi @@ -10,7 +10,7 @@ <MainUnit Value="0"/> <TargetFileExt Value=".exe"/> <Title Value="excel5read"/> - <ActiveEditorIndexAtStart Value="3"/> + <ActiveEditorIndexAtStart Value="0"/> </General> <VersionInfo> <ProjectVersion Value=""/> @@ -26,7 +26,7 @@ <RunParams> <local> <FormatVersion Value="1"/> - <LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/> + <LaunchingApplication PathPlusParams="\usr\X11R6\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/> </local> </RunParams> <RequiredPackages Count="1"> @@ -39,7 +39,7 @@ <Filename Value="excel5read.lpr"/> <IsPartOfProject Value="True"/> <UnitName Value="excel5read"/> - <CursorPos X="20" Y="30"/> + <CursorPos X="39" Y="43"/> <TopLine Value="21"/> <EditorIndex Value="0"/> <UsageCount Value="309"/> @@ -69,7 +69,7 @@ <Unit4> <Filename Value="..\..\xlsbiff5.pas"/> <UnitName Value="xlsbiff5"/> - <CursorPos X="53" Y="913"/> + <CursorPos X="19" Y="920"/> <TopLine Value="903"/> <EditorIndex Value="3"/> <UsageCount Value="140"/> @@ -97,7 +97,7 @@ <Filename Value="..\..\fpolestorage.pas"/> <UnitName Value="fpolestorage"/> <CursorPos X="78" Y="806"/> - <TopLine Value="798"/> + <TopLine Value="792"/> <EditorIndex Value="5"/> <UsageCount Value="139"/> <Loaded Value="True"/> @@ -150,7 +150,7 @@ <UsageCount Value="10"/> </Unit14> </Units> - <JumpHistory Count="30" HistoryIndex="29"> + <JumpHistory Count="29" HistoryIndex="28"> <Position1> <Filename Value="..\..\xlsbiff5.pas"/> <Caret Line="895" Column="1" TopLine="885"/> @@ -205,72 +205,68 @@ </Position13> <Position14> <Filename Value="..\..\xlsbiff5.pas"/> - <Caret Line="913" Column="3" TopLine="919"/> + <Caret Line="924" Column="1" TopLine="914"/> </Position14> <Position15> <Filename Value="..\..\xlsbiff5.pas"/> - <Caret Line="924" Column="1" TopLine="914"/> + <Caret Line="926" Column="1" TopLine="916"/> </Position15> <Position16> <Filename Value="..\..\xlsbiff5.pas"/> - <Caret Line="926" Column="1" TopLine="916"/> + <Caret Line="918" Column="1" TopLine="910"/> </Position16> <Position17> <Filename Value="..\..\xlsbiff5.pas"/> - <Caret Line="918" Column="1" TopLine="910"/> + <Caret Line="886" Column="1" TopLine="867"/> </Position17> <Position18> <Filename Value="..\..\xlsbiff5.pas"/> - <Caret Line="886" Column="1" TopLine="867"/> + <Caret Line="889" Column="1" TopLine="876"/> </Position18> <Position19> <Filename Value="..\..\xlsbiff5.pas"/> - <Caret Line="889" Column="1" TopLine="876"/> + <Caret Line="68" Column="24" TopLine="58"/> </Position19> <Position20> <Filename Value="..\..\xlsbiff5.pas"/> - <Caret Line="68" Column="24" TopLine="58"/> + <Caret Line="887" Column="1" TopLine="882"/> </Position20> <Position21> <Filename Value="..\..\xlsbiff5.pas"/> - <Caret Line="887" Column="1" TopLine="882"/> + <Caret Line="64" Column="37" TopLine="55"/> </Position21> <Position22> <Filename Value="..\..\xlsbiff5.pas"/> - <Caret Line="64" Column="37" TopLine="55"/> + <Caret Line="934" Column="5" TopLine="915"/> </Position22> <Position23> <Filename Value="..\..\xlsbiff5.pas"/> - <Caret Line="934" Column="5" TopLine="915"/> + <Caret Line="941" Column="23" TopLine="925"/> </Position23> <Position24> <Filename Value="..\..\xlsbiff5.pas"/> - <Caret Line="941" Column="23" TopLine="925"/> + <Caret Line="72" Column="25" TopLine="62"/> </Position24> <Position25> - <Filename Value="..\..\xlsbiff5.pas"/> - <Caret Line="72" Column="25" TopLine="62"/> - </Position25> - <Position26> <Filename Value="..\..\fpspreadsheet.pas"/> <Caret Line="499" Column="45" TopLine="486"/> + </Position25> + <Position26> + <Filename Value="..\..\xlsbiff5.pas"/> + <Caret Line="948" Column="1" TopLine="946"/> </Position26> <Position27> <Filename Value="..\..\xlsbiff5.pas"/> - <Caret Line="948" Column="1" TopLine="946"/> + <Caret Line="994" Column="12" TopLine="981"/> </Position27> <Position28> <Filename Value="..\..\xlsbiff5.pas"/> - <Caret Line="994" Column="12" TopLine="981"/> + <Caret Line="891" Column="1" TopLine="872"/> </Position28> <Position29> - <Filename Value="..\..\xlsbiff5.pas"/> - <Caret Line="891" Column="1" TopLine="872"/> - </Position29> - <Position30> <Filename Value="..\..\xlsbiff5.pas"/> <Caret Line="70" Column="15" TopLine="60"/> - </Position30> + </Position29> </JumpHistory> </ProjectOptions> <CompilerOptions> diff --git a/components/fpspreadsheet/examples/excel5demo/excel5read.lpr b/components/fpspreadsheet/examples/excel5demo/excel5read.lpr index c4625a342..aa566dfa4 100644 --- a/components/fpspreadsheet/examples/excel5demo/excel5read.lpr +++ b/components/fpspreadsheet/examples/excel5demo/excel5read.lpr @@ -40,7 +40,8 @@ begin begin CurCell := MyWorkSheet.GetCellByIndex(i); WriteLn('Row: ', CurCell^.Row, ' Col: ', CurCell^.Col, ' Value: ', - MyWorkSheet.ReadAsAnsiText(CurCell^.Row, CurCell^.Col)); + UTF8ToAnsi(MyWorkSheet.ReadAsUTF8Text(CurCell^.Row, CurCell^.Col)) + ); end; // Finalization diff --git a/components/fpspreadsheet/examples/excel5demo/excel5write.lpi b/components/fpspreadsheet/examples/excel5demo/excel5write.lpi index ab6d801d0..a6b230e4f 100644 --- a/components/fpspreadsheet/examples/excel5demo/excel5write.lpi +++ b/components/fpspreadsheet/examples/excel5demo/excel5write.lpi @@ -26,7 +26,7 @@ <RunParams> <local> <FormatVersion Value="1"/> - <LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/> + <LaunchingApplication PathPlusParams="\usr\X11R6\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/> </local> </RunParams> <RequiredPackages Count="1"> @@ -40,7 +40,7 @@ <IsPartOfProject Value="True"/> <UnitName Value="excel5write"/> <CursorPos X="8" Y="21"/> - <TopLine Value="52"/> + <TopLine Value="46"/> <EditorIndex Value="0"/> <UsageCount Value="309"/> <Loaded Value="True"/> diff --git a/components/fpspreadsheet/examples/excel5demo/excel5write.lpr b/components/fpspreadsheet/examples/excel5demo/excel5write.lpr index 036ae493d..accb4d33f 100644 --- a/components/fpspreadsheet/examples/excel5demo/excel5write.lpr +++ b/components/fpspreadsheet/examples/excel5demo/excel5write.lpr @@ -59,10 +59,10 @@ begin MyWorksheet := MyWorkbook.AddWorksheet('My Worksheet 2'); // Write some string cells - MyWorksheet.WriteAnsiText(0, 0, 'First'); - MyWorksheet.WriteAnsiText(0, 1, 'Second'); - MyWorksheet.WriteAnsiText(0, 2, 'Third'); - MyWorksheet.WriteAnsiText(0, 3, 'Fourth'); + MyWorksheet.WriteUTF8Text(0, 0, 'First'); + MyWorksheet.WriteUTF8Text(0, 1, 'Second'); + MyWorksheet.WriteUTF8Text(0, 2, 'Third'); + MyWorksheet.WriteUTF8Text(0, 3, 'Fourth'); // Save the spreadsheet to a file MyWorkbook.WriteToFile(MyDir + 'test' + STR_EXCEL_EXTENSION, sfExcel5); diff --git a/components/fpspreadsheet/fpspreadsheet.pas b/components/fpspreadsheet/fpspreadsheet.pas index e29ed1f6b..579c51c07 100755 --- a/components/fpspreadsheet/fpspreadsheet.pas +++ b/components/fpspreadsheet/fpspreadsheet.pas @@ -23,6 +23,8 @@ type const { Default extensions } STR_EXCEL_EXTENSION = '.xls'; + STR_OOXML_EXCEL_EXTENSION = '.xlsx'; + STR_OPENDOCUMENT_CALC_EXTENSION = '.ods'; const { TokenID values } @@ -59,7 +61,7 @@ type {@@ Describes the type of content of a cell on a TsWorksheet } - TCellContentType = (cctFormula, cctNumber, cctString, cctWideString); + TCellContentType = (cctFormula, cctNumber, cctUTF8String); {@@ Cell structure for TsWorksheet } @@ -68,8 +70,7 @@ type ContentType: TCellContentType; FormulaValue: TRPNFormula; NumberValue: double; - StringValue: string; - WideStringValue: widestring; + UTF8StringValue: ansistring; end; PCell = ^TCell; @@ -97,9 +98,9 @@ type function GetCell(ARow, ACol: Cardinal): PCell; function GetCellCount: Cardinal; function GetCellByIndex(AIndex: Cardinal): PCell; - function ReadAsAnsiText(ARow, ACol: Cardinal): ansistring; + function ReadAsUTF8Text(ARow, ACol: Cardinal): ansistring; procedure RemoveAllCells; - procedure WriteAnsiText(ARow, ACol: Cardinal; AText: ansistring); + procedure WriteUTF8Text(ARow, ACol: Cardinal; AText: ansistring); procedure WriteNumber(ARow, ACol: Cardinal; ANumber: double); procedure WriteRPNFormula(ARow, ACol: Cardinal; AFormula: TRPNFormula); end; @@ -352,15 +353,17 @@ begin end; {@@ - Reads the contents of a cell and converts it to a user readable text, - if it isn't already a text. + Reads the contents of a cell and returns an user readable text + representing the contents of the cell. + + The resulting ansistring is UTF-8 encoded. @param ARow The row of the cell @param ACol The column of the cell @return The text representation of the cell } -function TsWorksheet.ReadAsAnsiText(ARow, ACol: Cardinal): ansistring; +function TsWorksheet.ReadAsUTF8Text(ARow, ACol: Cardinal): ansistring; var ACell: PCell; begin @@ -376,10 +379,9 @@ begin //cctFormula cctNumber: Result := FloatToStr(ACell^.NumberValue); - cctString: Result := ACell^.StringValue; - cctWideString: Result := ACell^.WideStringValue; + cctUTF8String: Result := UTF8ToAnsi(ACell^.UTF8StringValue); else - Result := ACell^.StringValue; + Result := ''; end; end; @@ -392,25 +394,23 @@ begin end; {@@ - Writes ansi text to a determined cell. - - The text must be encoded on the system default encoding. - - On formats the support unicode the text will be converted to the unicode - encoding that the format supports. + Writes UTF-8 encoded text to a determined cell. + + On formats that only support unicode the text will be converted + to the unicode encoding that the format supports. @param ARow The row of the cell @param ACol The column of the cell @param AText The text to be written encoded with the system encoding } -procedure TsWorksheet.WriteAnsiText(ARow, ACol: Cardinal; AText: ansistring); +procedure TsWorksheet.WriteUTF8Text(ARow, ACol: Cardinal; AText: ansistring); var ACell: PCell; begin ACell := GetCell(ARow, ACol); - ACell^.ContentType := cctString; - ACell^.StringValue := AText; + ACell^.ContentType := cctUTF8String; + ACell^.UTF8StringValue := AText; end; {@@ @@ -714,7 +714,7 @@ begin case ACell.ContentType of cctFormula: WriteFormula(AStream, ACell^.Row, ACell^.Col, ACell^.FormulaValue); cctNumber: WriteNumber(AStream, ACell^.Row, ACell^.Col, ACell^.NumberValue); - cctString: WriteLabel(AStream, ACell^.Row, ACell^.Col, ACell^.StringValue); + cctUTF8String: WriteLabel(AStream, ACell^.Row, ACell^.Col, ACell^.UTF8StringValue); end; end; diff --git a/components/fpspreadsheet/xlsbiff2.pas b/components/fpspreadsheet/xlsbiff2.pas index bfc2a0b31..28c4eb4b6 100755 --- a/components/fpspreadsheet/xlsbiff2.pas +++ b/components/fpspreadsheet/xlsbiff2.pas @@ -240,8 +240,10 @@ procedure TsSpreadBIFF2Writer.WriteLabel(AStream: TStream; const ARow, ACol: Word; const AValue: string); var L: Byte; + AnsiText: ansistring; begin - L := Length(AValue); + AnsiText := UTF8ToAnsi(AValue); + L := Length(AnsiText); { BIFF Record header } AStream.WriteWord(WordToLE(INT_EXCEL_ID_LABEL)); @@ -258,7 +260,7 @@ begin { String with 8-bit size } AStream.WriteByte(L); - AStream.WriteBuffer(AValue[1], L); + AStream.WriteBuffer(AnsiText[1], L); end; {******************************************************************* @@ -357,7 +359,7 @@ begin AStrValue := AValue; { Save the data } - FWorksheet.WriteAnsiText(ARow, ACol, AStrValue); + FWorksheet.WriteUTF8Text(ARow, ACol, AnsiToUTF8(AStrValue)); end; procedure TsSpreadBIFF2Reader.ReadNumber(AStream: TStream); diff --git a/components/fpspreadsheet/xlsbiff5.pas b/components/fpspreadsheet/xlsbiff5.pas index cf8b7d196..8e7c330bd 100755 --- a/components/fpspreadsheet/xlsbiff5.pas +++ b/components/fpspreadsheet/xlsbiff5.pas @@ -657,8 +657,10 @@ procedure TsSpreadBIFF5Writer.WriteLabel(AStream: TStream; const ARow, ACol: Word; const AValue: string); var L: Word; + AnsiValue: ansistring; begin - L := Length(AValue); + AnsiValue := UTF8ToAnsi(AValue); + L := Length(AnsiValue); { BIFF Record header } AStream.WriteWord(WordToLE(INT_EXCEL_ID_LABEL)); @@ -673,7 +675,7 @@ begin { Byte String with 16-bit size } AStream.WriteWord(L); - AStream.WriteBuffer(AValue[1], L); + AStream.WriteBuffer(AnsiValue[1], L); end; {*******************************************************************