diff --git a/components/fpspreadsheet/examples/excel2demo/excel2read.lpi b/components/fpspreadsheet/examples/excel2demo/excel2read.lpi index a620de222..607bca344 100644 --- a/components/fpspreadsheet/examples/excel2demo/excel2read.lpi +++ b/components/fpspreadsheet/examples/excel2demo/excel2read.lpi @@ -10,7 +10,7 @@ - <ActiveEditorIndexAtStart Value="4"/> + <ActiveEditorIndexAtStart Value="3"/> </General> <VersionInfo> <ProjectVersion Value=""/> @@ -69,8 +69,8 @@ <Unit4> <Filename Value="..\..\xlsbiff5.pas"/> <UnitName Value="xlsbiff5"/> - <CursorPos X="29" Y="1"/> - <TopLine Value="22"/> + <CursorPos X="37" Y="934"/> + <TopLine Value="918"/> <EditorIndex Value="3"/> <UsageCount Value="140"/> <Loaded Value="True"/> @@ -78,8 +78,8 @@ <Unit5> <Filename Value="..\..\fpsutils.pas"/> <UnitName Value="fpsutils"/> - <CursorPos X="1" Y="49"/> - <TopLine Value="30"/> + <CursorPos X="10" Y="15"/> + <TopLine Value="5"/> <EditorIndex Value="2"/> <UsageCount Value="140"/> <Loaded Value="True"/> @@ -87,8 +87,8 @@ <Unit6> <Filename Value="..\..\xlsbiff2.pas"/> <UnitName Value="xlsbiff2"/> - <CursorPos X="16" Y="357"/> - <TopLine Value="347"/> + <CursorPos X="1" Y="311"/> + <TopLine Value="293"/> <EditorIndex Value="4"/> <UsageCount Value="139"/> <Loaded Value="True"/> @@ -96,8 +96,8 @@ <Unit7> <Filename Value="..\..\fpolestorage.pas"/> <UnitName Value="fpolestorage"/> - <CursorPos X="30" Y="654"/> - <TopLine Value="642"/> + <CursorPos X="12" Y="748"/> + <TopLine Value="766"/> <EditorIndex Value="5"/> <UsageCount Value="139"/> <Loaded Value="True"/> @@ -120,7 +120,7 @@ <CursorPos X="2" Y="714"/> <TopLine Value="701"/> <EditorIndex Value="1"/> - <UsageCount Value="92"/> + <UsageCount Value="93"/> <Loaded Value="True"/> </Unit10> <Unit11> @@ -139,123 +139,123 @@ <JumpHistory Count="30" HistoryIndex="29"> <Position1> <Filename Value="..\..\xlsbiff2.pas"/> - <Caret Line="309" Column="1" TopLine="299"/> + <Caret Line="312" Column="1" TopLine="302"/> </Position1> <Position2> <Filename Value="..\..\xlsbiff2.pas"/> - <Caret Line="310" Column="1" TopLine="300"/> + <Caret Line="314" Column="1" TopLine="304"/> </Position2> <Position3> <Filename Value="..\..\xlsbiff2.pas"/> - <Caret Line="312" Column="1" TopLine="302"/> + <Caret Line="317" Column="1" TopLine="307"/> </Position3> <Position4> <Filename Value="..\..\xlsbiff2.pas"/> - <Caret Line="314" Column="1" TopLine="304"/> + <Caret Line="326" Column="1" TopLine="316"/> </Position4> <Position5> <Filename Value="..\..\xlsbiff2.pas"/> - <Caret Line="317" Column="1" TopLine="307"/> + <Caret Line="328" Column="1" TopLine="318"/> </Position5> <Position6> <Filename Value="..\..\xlsbiff2.pas"/> - <Caret Line="326" Column="1" TopLine="316"/> + <Caret Line="309" Column="1" TopLine="299"/> </Position6> <Position7> <Filename Value="..\..\xlsbiff2.pas"/> - <Caret Line="328" Column="1" TopLine="318"/> + <Caret Line="310" Column="1" TopLine="300"/> </Position7> <Position8> <Filename Value="..\..\xlsbiff2.pas"/> - <Caret Line="309" Column="1" TopLine="299"/> + <Caret Line="312" Column="1" TopLine="302"/> </Position8> <Position9> <Filename Value="..\..\xlsbiff2.pas"/> - <Caret Line="310" Column="1" TopLine="300"/> + <Caret Line="314" Column="1" TopLine="304"/> </Position9> <Position10> <Filename Value="..\..\xlsbiff2.pas"/> - <Caret Line="312" Column="1" TopLine="302"/> + <Caret Line="317" Column="1" TopLine="307"/> </Position10> <Position11> <Filename Value="..\..\xlsbiff2.pas"/> - <Caret Line="314" Column="1" TopLine="304"/> + <Caret Line="326" Column="1" TopLine="316"/> </Position11> <Position12> <Filename Value="..\..\xlsbiff2.pas"/> - <Caret Line="317" Column="1" TopLine="307"/> + <Caret Line="328" Column="1" TopLine="318"/> </Position12> <Position13> <Filename Value="..\..\xlsbiff2.pas"/> - <Caret Line="326" Column="1" TopLine="316"/> + <Caret Line="309" Column="1" TopLine="299"/> </Position13> <Position14> <Filename Value="..\..\xlsbiff2.pas"/> - <Caret Line="328" Column="1" TopLine="318"/> + <Caret Line="310" Column="1" TopLine="300"/> </Position14> <Position15> <Filename Value="..\..\xlsbiff2.pas"/> - <Caret Line="309" Column="1" TopLine="299"/> + <Caret Line="312" Column="1" TopLine="302"/> </Position15> <Position16> <Filename Value="..\..\xlsbiff2.pas"/> - <Caret Line="310" Column="1" TopLine="300"/> + <Caret Line="314" Column="1" TopLine="304"/> </Position16> <Position17> <Filename Value="..\..\xlsbiff2.pas"/> - <Caret Line="312" Column="1" TopLine="302"/> + <Caret Line="320" Column="1" TopLine="310"/> </Position17> <Position18> <Filename Value="..\..\xlsbiff2.pas"/> - <Caret Line="314" Column="1" TopLine="304"/> + <Caret Line="100" Column="16" TopLine="87"/> </Position18> <Position19> <Filename Value="..\..\xlsbiff2.pas"/> - <Caret Line="317" Column="1" TopLine="307"/> + <Caret Line="357" Column="16" TopLine="348"/> </Position19> <Position20> <Filename Value="..\..\xlsbiff2.pas"/> - <Caret Line="326" Column="1" TopLine="316"/> + <Caret Line="354" Column="6" TopLine="344"/> </Position20> <Position21> <Filename Value="..\..\xlsbiff2.pas"/> - <Caret Line="328" Column="1" TopLine="318"/> + <Caret Line="356" Column="14" TopLine="340"/> </Position21> <Position22> - <Filename Value="..\..\xlsbiff2.pas"/> - <Caret Line="309" Column="1" TopLine="299"/> + <Filename Value="..\..\fpsutils.pas"/> + <Caret Line="48" Column="20" TopLine="34"/> </Position22> <Position23> - <Filename Value="..\..\xlsbiff2.pas"/> - <Caret Line="310" Column="1" TopLine="300"/> + <Filename Value="..\..\fpsutils.pas"/> + <Caret Line="11" Column="3" TopLine="1"/> </Position23> <Position24> - <Filename Value="..\..\xlsbiff2.pas"/> - <Caret Line="312" Column="1" TopLine="302"/> + <Filename Value="..\..\fpsutils.pas"/> + <Caret Line="90" Column="5" TopLine="71"/> </Position24> <Position25> - <Filename Value="..\..\xlsbiff2.pas"/> - <Caret Line="314" Column="1" TopLine="304"/> + <Filename Value="..\..\fpolestorage.pas"/> + <Caret Line="654" Column="30" TopLine="642"/> </Position25> <Position26> - <Filename Value="..\..\xlsbiff2.pas"/> - <Caret Line="320" Column="1" TopLine="310"/> + <Filename Value="..\..\fpolestorage.pas"/> + <Caret Line="218" Column="24" TopLine="210"/> </Position26> <Position27> <Filename Value="..\..\xlsbiff2.pas"/> - <Caret Line="100" Column="16" TopLine="87"/> + <Caret Line="355" Column="6" TopLine="347"/> </Position27> <Position28> <Filename Value="..\..\xlsbiff2.pas"/> - <Caret Line="357" Column="16" TopLine="348"/> + <Caret Line="123" Column="26" TopLine="106"/> </Position28> <Position29> - <Filename Value="..\..\xlsbiff2.pas"/> - <Caret Line="354" Column="6" TopLine="344"/> + <Filename Value="..\..\fpsutils.pas"/> + <Caret Line="69" Column="5" TopLine="50"/> </Position29> <Position30> - <Filename Value="..\..\xlsbiff2.pas"/> - <Caret Line="356" Column="14" TopLine="340"/> + <Filename Value="..\..\xlsbiff5.pas"/> + <Caret Line="901" Column="1" TopLine="882"/> </Position30> </JumpHistory> </ProjectOptions> diff --git a/components/fpspreadsheet/examples/excel5demo/excel5read.lpi b/components/fpspreadsheet/examples/excel5demo/excel5read.lpi index 62ada40a3..e1a456364 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="1"/> + <ActiveEditorIndexAtStart Value="3"/> </General> <VersionInfo> <ProjectVersion Value=""/> @@ -39,8 +39,8 @@ <Filename Value="excel5read.lpr"/> <IsPartOfProject Value="True"/> <UnitName Value="excel5read"/> - <CursorPos X="1" Y="21"/> - <TopLine Value="3"/> + <CursorPos X="16" Y="38"/> + <TopLine Value="30"/> <EditorIndex Value="0"/> <UsageCount Value="309"/> <Loaded Value="True"/> @@ -69,8 +69,8 @@ <Unit4> <Filename Value="..\..\xlsbiff5.pas"/> <UnitName Value="xlsbiff5"/> - <CursorPos X="15" Y="64"/> - <TopLine Value="54"/> + <CursorPos X="1" Y="910"/> + <TopLine Value="904"/> <EditorIndex Value="3"/> <UsageCount Value="140"/> <Loaded Value="True"/> @@ -87,8 +87,8 @@ <Unit6> <Filename Value="..\..\xlsbiff2.pas"/> <UnitName Value="xlsbiff2"/> - <CursorPos X="1" Y="69"/> - <TopLine Value="57"/> + <CursorPos X="1" Y="365"/> + <TopLine Value="363"/> <EditorIndex Value="4"/> <UsageCount Value="139"/> <Loaded Value="True"/> @@ -96,8 +96,8 @@ <Unit7> <Filename Value="..\..\fpolestorage.pas"/> <UnitName Value="fpolestorage"/> - <CursorPos X="30" Y="654"/> - <TopLine Value="642"/> + <CursorPos X="78" Y="806"/> + <TopLine Value="798"/> <EditorIndex Value="5"/> <UsageCount Value="139"/> <Loaded Value="True"/> @@ -117,8 +117,8 @@ <Unit10> <Filename Value="..\..\fpspreadsheet.pas"/> <UnitName Value="fpspreadsheet"/> - <CursorPos X="1" Y="197"/> - <TopLine Value="189"/> + <CursorPos X="47" Y="149"/> + <TopLine Value="133"/> <EditorIndex Value="1"/> <UsageCount Value="92"/> <Loaded Value="True"/> @@ -138,124 +138,124 @@ </Units> <JumpHistory Count="30" HistoryIndex="29"> <Position1> - <Filename Value="..\..\fpolestorage.pas"/> - <Caret Line="486" Column="5" TopLine="467"/> - </Position1> - <Position2> - <Filename Value="..\..\fpolestorage.pas"/> - <Caret Line="510" Column="5" TopLine="491"/> - </Position2> - <Position3> - <Filename Value="..\..\fpolestorage.pas"/> - <Caret Line="94" Column="46" TopLine="84"/> - </Position3> - <Position4> - <Filename Value="..\..\fpolestorage.pas"/> - <Caret Line="686" Column="5" TopLine="667"/> - </Position4> - <Position5> - <Filename Value="..\..\fpolestorage.pas"/> - <Caret Line="567" Column="5" TopLine="548"/> - </Position5> - <Position6> - <Filename Value="..\..\fpolestorage.pas"/> - <Caret Line="622" Column="1" TopLine="618"/> - </Position6> - <Position7> - <Filename Value="..\..\fpolestorage.pas"/> - <Caret Line="621" Column="29" TopLine="611"/> - </Position7> - <Position8> - <Filename Value="excel5read.lpr"/> - <Caret Line="40" Column="17" TopLine="29"/> - </Position8> - <Position9> - <Filename Value="..\..\fpspreadsheet.pas"/> - <Caret Line="85" Column="3" TopLine="83"/> - </Position9> - <Position10> - <Filename Value="..\..\fpspreadsheet.pas"/> - <Caret Line="304" Column="5" TopLine="293"/> - </Position10> - <Position11> - <Filename Value="..\..\fpspreadsheet.pas"/> - <Caret Line="319" Column="32" TopLine="305"/> - </Position11> - <Position12> - <Filename Value="..\..\fpspreadsheet.pas"/> - <Caret Line="363" Column="15" TopLine="349"/> - </Position12> - <Position13> - <Filename Value="..\..\fpspreadsheet.pas"/> - <Caret Line="362" Column="36" TopLine="353"/> - </Position13> - <Position14> - <Filename Value="excel5read.lpr"/> - <Caret Line="40" Column="17" TopLine="29"/> - </Position14> - <Position15> - <Filename Value="excel5read.lpr"/> - <Caret Line="24" Column="1" TopLine="13"/> - </Position15> - <Position16> - <Filename Value="excel5read.lpr"/> - <Caret Line="29" Column="6" TopLine="19"/> - </Position16> - <Position17> - <Filename Value="excel5read.lpr"/> - <Caret Line="16" Column="17" TopLine="6"/> - </Position17> - <Position18> - <Filename Value="..\..\fpspreadsheet.pas"/> - <Caret Line="110" Column="3" TopLine="108"/> - </Position18> - <Position19> - <Filename Value="..\..\fpspreadsheet.pas"/> - <Caret Line="475" Column="5" TopLine="456"/> - </Position19> - <Position20> - <Filename Value="..\..\fpspreadsheet.pas"/> - <Caret Line="505" Column="42" TopLine="496"/> - </Position20> - <Position21> - <Filename Value="..\..\fpspreadsheet.pas"/> - <Caret Line="175" Column="24" TopLine="165"/> - </Position21> - <Position22> - <Filename Value="excel5read.lpr"/> - <Caret Line="16" Column="17" TopLine="6"/> - </Position22> - <Position23> - <Filename Value="..\..\fpspreadsheet.pas"/> - <Caret Line="143" Column="15" TopLine="115"/> - </Position23> - <Position24> <Filename Value="..\..\fpspreadsheet.pas"/> <Caret Line="119" Column="67" TopLine="108"/> - </Position24> - <Position25> + </Position1> + <Position2> <Filename Value="..\..\fpspreadsheet.pas"/> <Caret Line="485" Column="42" TopLine="474"/> - </Position25> - <Position26> + </Position2> + <Position3> <Filename Value="..\..\fpspreadsheet.pas"/> <Caret Line="161" Column="3" TopLine="159"/> - </Position26> - <Position27> + </Position3> + <Position4> <Filename Value="..\..\fpspreadsheet.pas"/> <Caret Line="141" Column="3" TopLine="139"/> - </Position27> - <Position28> + </Position4> + <Position5> <Filename Value="..\..\fpspreadsheet.pas"/> <Caret Line="669" Column="20" TopLine="658"/> - </Position28> - <Position29> + </Position5> + <Position6> <Filename Value="..\..\fpspreadsheet.pas"/> <Caret Line="158" Column="15" TopLine="143"/> - </Position29> - <Position30> + </Position6> + <Position7> <Filename Value="..\..\fpspreadsheet.pas"/> <Caret Line="116" Column="71" TopLine="106"/> + </Position7> + <Position8> + <Filename Value="..\..\xlsbiff5.pas"/> + <Caret Line="886" Column="1" TopLine="876"/> + </Position8> + <Position9> + <Filename Value="..\..\xlsbiff5.pas"/> + <Caret Line="888" Column="1" TopLine="878"/> + </Position9> + <Position10> + <Filename Value="..\..\xlsbiff5.pas"/> + <Caret Line="891" Column="1" TopLine="881"/> + </Position10> + <Position11> + <Filename Value="..\..\xlsbiff5.pas"/> + <Caret Line="894" Column="1" TopLine="884"/> + </Position11> + <Position12> + <Filename Value="..\..\xlsbiff5.pas"/> + <Caret Line="895" Column="1" TopLine="885"/> + </Position12> + <Position13> + <Filename Value="..\..\xlsbiff5.pas"/> + <Caret Line="897" Column="1" TopLine="887"/> + </Position13> + <Position14> + <Filename Value="..\..\xlsbiff5.pas"/> + <Caret Line="899" Column="1" TopLine="889"/> + </Position14> + <Position15> + <Filename Value="..\..\xlsbiff5.pas"/> + <Caret Line="904" Column="14" TopLine="895"/> + </Position15> + <Position16> + <Filename Value="..\..\fpolestorage.pas"/> + <Caret Line="768" Column="1" TopLine="765"/> + </Position16> + <Position17> + <Filename Value="..\..\xlsbiff5.pas"/> + <Caret Line="886" Column="1" TopLine="876"/> + </Position17> + <Position18> + <Filename Value="..\..\xlsbiff5.pas"/> + <Caret Line="888" Column="1" TopLine="878"/> + </Position18> + <Position19> + <Filename Value="..\..\xlsbiff5.pas"/> + <Caret Line="891" Column="1" TopLine="881"/> + </Position19> + <Position20> + <Filename Value="..\..\xlsbiff5.pas"/> + <Caret Line="886" Column="1" TopLine="867"/> + </Position20> + <Position21> + <Filename Value="..\..\xlsbiff5.pas"/> + <Caret Line="894" Column="1" TopLine="882"/> + </Position21> + <Position22> + <Filename Value="..\..\xlsbiff5.pas"/> + <Caret Line="64" Column="41" TopLine="60"/> + </Position22> + <Position23> + <Filename Value="..\..\xlsbiff5.pas"/> + <Caret Line="70" Column="24" TopLine="60"/> + </Position23> + <Position24> + <Filename Value="..\..\fpolestorage.pas"/> + <Caret Line="797" Column="16" TopLine="784"/> + </Position24> + <Position25> + <Filename Value="..\..\fpolestorage.pas"/> + <Caret Line="670" Column="37" TopLine="655"/> + </Position25> + <Position26> + <Filename Value="..\..\fpolestorage.pas"/> + <Caret Line="666" Column="13" TopLine="659"/> + </Position26> + <Position27> + <Filename Value="..\..\xlsbiff5.pas"/> + <Caret Line="895" Column="1" TopLine="885"/> + </Position27> + <Position28> + <Filename Value="..\..\xlsbiff5.pas"/> + <Caret Line="908" Column="1" TopLine="898"/> + </Position28> + <Position29> + <Filename Value="..\..\xlsbiff5.pas"/> + <Caret Line="910" Column="1" TopLine="900"/> + </Position29> + <Position30> + <Filename Value="..\..\xlsbiff5.pas"/> + <Caret Line="913" Column="1" TopLine="903"/> </Position30> </JumpHistory> </ProjectOptions> @@ -270,4 +270,12 @@ <CompilerPath Value="$(CompPath)"/> </Other> </CompilerOptions> + <Debugging> + <BreakPoints Count="1"> + <Item1> + <Source Value="..\..\xlsbiff5.pas"/> + <Line Value="910"/> + </Item1> + </BreakPoints> + </Debugging> </CONFIG> diff --git a/components/fpspreadsheet/examples/excel5demo/excel5read.lpr b/components/fpspreadsheet/examples/excel5demo/excel5read.lpr index 044527a24..c4625a342 100644 --- a/components/fpspreadsheet/examples/excel5demo/excel5read.lpr +++ b/components/fpspreadsheet/examples/excel5demo/excel5read.lpr @@ -36,7 +36,7 @@ begin WriteLn('Contents of the first worksheet of the file:'); WriteLn(''); - for i := 0 to MyWorksheet.GetCellCount do + for i := 0 to MyWorksheet.GetCellCount - 1 do begin CurCell := MyWorkSheet.GetCellByIndex(i); WriteLn('Row: ', CurCell^.Row, ' Col: ', CurCell^.Col, ' Value: ', diff --git a/components/fpspreadsheet/fpolestorage.pas b/components/fpspreadsheet/fpolestorage.pas index fc551193e..b1566149e 100755 --- a/components/fpspreadsheet/fpolestorage.pas +++ b/components/fpspreadsheet/fpolestorage.pas @@ -623,7 +623,7 @@ begin AStream.ReadDWord(); AStream.ReadDWord(); - AIsStorage := AStream.ReadDWord() <> $FFFFFFFF; + AIsStorage := DWordLEtoN(AStream.ReadDWord) <> $FFFFFFFF; {Root Storage #1 00000470H XX XX XX XX 03 00 00 00 40 03 00 00 00 00 00 00 @@ -649,9 +649,9 @@ begin AStream.Seek(BaseAddr + $74, soFromBeginning); - AFirstSecID := AStream.ReadDWord(); + AFirstSecID := DWordLEtoN(AStream.ReadDWord); - AStreamSize := AStream.ReadDWord(); + AStreamSize := DWordLEtoN(AStream.ReadDWord); AStream.ReadDWord(); end; @@ -662,8 +662,12 @@ begin end; procedure TOLEStorage.ReadUserStream(ADest, ASource: TStream); +var + i: Integer; begin - ADest.CopyFrom(ASource, FReadingStreamSize); +// ADest.CopyFrom(ASource, FReadingStreamSize); + for i := 1 to FReadingStreamSize do + ADest.WriteByte(ASource.ReadByte); end; constructor TOLEStorage.Create; @@ -753,7 +757,7 @@ begin end; {@@ - Reads an OLE file. Experimental + Reads an OLE file. } procedure TOLEStorage.ReadOLEFile(AFileName: string; AOLEDocument: TOLEDocument); @@ -761,6 +765,7 @@ var AFileStream: TFileStream; CurrentSectorPos: Int64; begin + FOLEDocument := AOLEDocument; AOLEDocument.Stream := TMemoryStream.Create; AFileStream := TFileStream.Create(AFileName, fmOpenRead); try @@ -800,9 +805,12 @@ begin end; end; +{@@ + Frees all internal objects storable in a TOLEDocument structure +} procedure TOLEStorage.FreeOLEDocumentData(AOLEDocument: TOLEDocument); begin - AOLEDocument.Stream.Free; + if Assigned(AOLEDocument.Stream) then FreeAndNil(AOLEDocument.Stream); end; end. diff --git a/components/fpspreadsheet/fpsutils.pas b/components/fpspreadsheet/fpsutils.pas index fcb7b548c..81aa77861 100644 --- a/components/fpspreadsheet/fpsutils.pas +++ b/components/fpspreadsheet/fpsutils.pas @@ -11,6 +11,9 @@ function WordToLE(AValue: Word): Word; function DWordToLE(AValue: Cardinal): Cardinal; function IntegerToLE(AValue: Integer): Integer; +function WordLEtoN(AValue: Word): Word; +function DWordLEtoN(AValue: Cardinal): Cardinal; + implementation { @@ -19,12 +22,19 @@ implementation Excel files are all written with Little Endian byte order, so it's necessary to swap the data to be able to build a correct file on big endian systems. + + These routines are preferable to System unit routines because they + ensure that the correct overloaded version of the conversion routines + will be used, avoiding typecasts which are less readable. + + They also guarantee delphi compatibility. For Delphi we just support + big-endian isn't support, because Delphi doesn't support it. } function WordToLE(AValue: Word): Word; begin - {$IFDEF BIG_ENDIAN} - Result := ((AValue shl 8) and $FF00) or ((AValue shr 8) and $00FF); + {$IFDEF FPC} + Result := NtoLE(AValue); {$ELSE} Result := AValue; {$ENDIF} @@ -32,8 +42,8 @@ end; function DWordToLE(AValue: Cardinal): Cardinal; begin - {$IFDEF BIG_ENDIAN} -// ?? Result := ((AValue shl 8) and $FF00) or ((AValue shr 8) and $00FF); + {$IFDEF FPC} + Result := NtoLE(AValue); {$ELSE} Result := AValue; {$ENDIF} @@ -41,8 +51,26 @@ end; function IntegerToLE(AValue: Integer): Integer; begin - {$IFDEF BIG_ENDIAN} -// ?? Result := ((AValue shl 8) and $FF00) or ((AValue shr 8) and $00FF); + {$IFDEF FPC} + Result := NtoLE(AValue); + {$ELSE} + Result := AValue; + {$ENDIF} +end; + +function WordLEtoN(AValue: Word): Word; +begin + {$IFDEF FPC} + Result := LEtoN(AValue); + {$ELSE} + Result := AValue; + {$ENDIF} +end; + +function DWordLEtoN(AValue: Cardinal): Cardinal; +begin + {$IFDEF FPC} + Result := LEtoN(AValue); {$ELSE} Result := AValue; {$ENDIF} diff --git a/components/fpspreadsheet/xlsbiff2.pas b/components/fpspreadsheet/xlsbiff2.pas index a15f5b754..bfc2a0b31 100755 --- a/components/fpspreadsheet/xlsbiff2.pas +++ b/components/fpspreadsheet/xlsbiff2.pas @@ -306,8 +306,8 @@ begin while not BIFF2EOF do begin { Read the record header } - RecordType := AStream.ReadWord; - RecordSize := AStream.ReadWord; + RecordType := WordLEToN(AStream.ReadWord); + RecordSize := WordLEToN(AStream.ReadWord); CurStreamPos := AStream.Position; @@ -342,8 +342,8 @@ var AStrValue: ansistring; begin { BIFF Record data } - ARow := AStream.ReadWord(); - ACol := AStream.ReadWord(); + ARow := WordLEToN(AStream.ReadWord); + ACol := WordLEToN(AStream.ReadWord); { BIFF2 Attributes } AStream.ReadByte(); @@ -366,8 +366,8 @@ var AValue: Double; begin { BIFF Record data } - ARow := AStream.ReadWord(); - ACol := AStream.ReadWord(); + ARow := WordLEToN(AStream.ReadWord); + ACol := WordLEToN(AStream.ReadWord); { BIFF2 Attributes } AStream.ReadByte(); diff --git a/components/fpspreadsheet/xlsbiff5.pas b/components/fpspreadsheet/xlsbiff5.pas index b138a40f5..32df68798 100755 --- a/components/fpspreadsheet/xlsbiff5.pas +++ b/components/fpspreadsheet/xlsbiff5.pas @@ -59,6 +59,22 @@ uses type + { TsSpreadBIFF5Reader } + + TsSpreadBIFF5Reader = class(TsCustomSpreadReader) + private + RecordSize: Word; + FWorksheet: TsWorksheet; + public + { General reading methods } + procedure ReadFromFile(AFileName: string; AData: TsWorkbook); override; + procedure ReadFromStream(AStream: TStream; AData: TsWorkbook); override; + { Record writing methods } + procedure ReadFormula(AStream: TStream); override; + procedure ReadLabel(AStream: TStream); override; + procedure ReadNumber(AStream: TStream); override; + end; + { TsSpreadBIFF5Writer } TsSpreadBIFF5Writer = class(TsCustomSpreadWriter) @@ -859,9 +875,101 @@ end; * Registers this reader / writer on fpSpreadsheet * *******************************************************************} + +{ TsSpreadBIFF5Reader } + +procedure TsSpreadBIFF5Reader.ReadFromFile(AFileName: string; AData: TsWorkbook); +var + MemStream: TMemoryStream; + OLEStorage: TOLEStorage; + OLEDocument: TOLEDocument; +begin + MemStream := TMemoryStream.Create; + OLEStorage := TOLEStorage.Create; + try + // Only one stream is necessary for any number of worksheets + OLEDocument.Stream := MemStream; + + OLEStorage.ReadOLEFile(AFileName, OLEDocument); + + // Rewind the stream and read from it + MemStream.Position := 0; + ReadFromStream(MemStream, AData); + finally + MemStream.Free; + OLEStorage.Free; + end; +end; + +procedure TsSpreadBIFF5Reader.ReadFromStream(AStream: TStream; AData: TsWorkbook); +var + BIFF5EOF: Boolean; + RecordType: Word; + CurStreamPos: Int64; +begin + BIFF5EOF := False; + + FWorksheet := AData.AddWorksheet(''); + + { Read all records in a loop } + while not BIFF5EOF do + begin + { Read the record header } + RecordType := WordLEToN(AStream.ReadWord); + RecordSize := WordLEToN(AStream.ReadWord); + + CurStreamPos := AStream.Position; + + case RecordType of + + INT_EXCEL_ID_NUMBER: ReadNumber(AStream); + INT_EXCEL_ID_LABEL: ReadLabel(AStream); + INT_EXCEL_ID_FORMULA: ReadFormula(AStream); + INT_EXCEL_ID_BOF: ; + INT_EXCEL_ID_EOF: BIFF5EOF := True; + else + // nothing + end; + + // Make sure we are in the right position for the next record + AStream.Seek(CurStreamPos + RecordSize, soFromBeginning); + + if AStream.Position >= AStream.Size then BIFF5EOF := True; + end; +end; + +procedure TsSpreadBIFF5Reader.ReadFormula(AStream: TStream); +begin + +end; + +procedure TsSpreadBIFF5Reader.ReadLabel(AStream: TStream); +begin + +end; + +procedure TsSpreadBIFF5Reader.ReadNumber(AStream: TStream); +var + ARow, ACol: Word; + AValue: Double; +begin + { BIFF Record data } + ARow := WordLEToN(AStream.ReadWord); + ACol := WordLEToN(AStream.ReadWord); + + { Index to XF record } + AStream.ReadWord(); + + { IEE 754 floating-point value } + AStream.ReadBuffer(AValue, 8); + + { Save the data } + FWorksheet.WriteNumber(ARow, ACol, AValue); +end; + initialization - RegisterSpreadFormat(TsCustomSpreadReader, TsSpreadBIFF5Writer, sfExcel5); + RegisterSpreadFormat(TsSpreadBIFF5Reader, TsSpreadBIFF5Writer, sfExcel5); end.