You've already forked lazarus-ccr
fpspreadsheet: Support reading of BIFF2 files with BOF record of BIFF8 - there seem to exist some malformed files of this kind which can be read by Excel.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8768 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -53,6 +53,7 @@
|
|||||||
<Filename Value="excel2write"/>
|
<Filename Value="excel2write"/>
|
||||||
</Target>
|
</Target>
|
||||||
<SearchPaths>
|
<SearchPaths>
|
||||||
|
<IncludeFiles Value="..\..\..\source"/>
|
||||||
<OtherUnitFiles Value="..\..\..\source\common"/>
|
<OtherUnitFiles Value="..\..\..\source\common"/>
|
||||||
<UnitOutputDirectory Value="..\..\lib\$(TargetCPU)-$(TargetOS)"/>
|
<UnitOutputDirectory Value="..\..\lib\$(TargetCPU)-$(TargetOS)"/>
|
||||||
</SearchPaths>
|
</SearchPaths>
|
||||||
|
@ -194,6 +194,7 @@ const
|
|||||||
INT_EXCEL_ID_BOOLERROR = $0005;
|
INT_EXCEL_ID_BOOLERROR = $0005;
|
||||||
INT_EXCEL_ID_ROW = $0008;
|
INT_EXCEL_ID_ROW = $0008;
|
||||||
INT_EXCEL_ID_BOF = $0009;
|
INT_EXCEL_ID_BOF = $0009;
|
||||||
|
INT_EXCEL_ID_BOF_BIFF8 = $0809;
|
||||||
{%H-}INT_EXCEL_ID_INDEX = $000B;
|
{%H-}INT_EXCEL_ID_INDEX = $000B;
|
||||||
INT_EXCEL_ID_FORMAT = $001E;
|
INT_EXCEL_ID_FORMAT = $001E;
|
||||||
INT_EXCEL_ID_FORMATCOUNT = $001F;
|
INT_EXCEL_ID_FORMATCOUNT = $001F;
|
||||||
@ -340,6 +341,8 @@ class function TsSpreadBIFF2Reader.CheckFileFormat(AStream: TStream): Boolean;
|
|||||||
const
|
const
|
||||||
BIFF2_HEADER: packed array[0..3] of byte = (
|
BIFF2_HEADER: packed array[0..3] of byte = (
|
||||||
$09,$00, $04,$00); // they are common to all BIFF2 files that I've seen
|
$09,$00, $04,$00); // they are common to all BIFF2 files that I've seen
|
||||||
|
BIFF8_BOF: packed array[0..1] of byte = (
|
||||||
|
$09,$08); // some files begin with the BOF of BIFF8 (don't know whether there are BIFF5 BOFs as well...)
|
||||||
var
|
var
|
||||||
P: Int64;
|
P: Int64;
|
||||||
buf: packed array[0..3] of byte = (0, 0, 0, 0);
|
buf: packed array[0..3] of byte = (0, 0, 0, 0);
|
||||||
@ -352,10 +355,7 @@ begin
|
|||||||
n := AStream.Read(buf, SizeOf(buf));
|
n := AStream.Read(buf, SizeOf(buf));
|
||||||
if n < Length(BIFF2_HEADER) then
|
if n < Length(BIFF2_HEADER) then
|
||||||
exit;
|
exit;
|
||||||
for n:=0 to High(buf) do
|
Result := CompareMem(@buf[0], @BIFF2_HEADER, 4) or CompareMem(@buf[0], @BIFF8_BOF, 2);
|
||||||
if buf[n] <> BIFF2_HEADER[n] then
|
|
||||||
exit;
|
|
||||||
Result := true;
|
|
||||||
finally
|
finally
|
||||||
AStream.Position := P;
|
AStream.Position := P;
|
||||||
end;
|
end;
|
||||||
@ -656,6 +656,10 @@ begin
|
|||||||
case RecordType of
|
case RecordType of
|
||||||
INT_EXCEL_ID_BLANK : ReadBlank(AStream);
|
INT_EXCEL_ID_BLANK : ReadBlank(AStream);
|
||||||
INT_EXCEL_ID_BOF : BOFFound := true;
|
INT_EXCEL_ID_BOF : BOFFound := true;
|
||||||
|
INT_EXCEL_ID_BOF_BIFF8 : begin
|
||||||
|
BOFFound := true;
|
||||||
|
FWorkbook.AddErrorMsg('Incorrect file header.');
|
||||||
|
end;
|
||||||
INT_EXCEL_ID_BOOLERROR : ReadBool(AStream);
|
INT_EXCEL_ID_BOOLERROR : ReadBool(AStream);
|
||||||
INT_EXCEL_ID_BOTTOMMARGIN : ReadMargin(AStream, 3);
|
INT_EXCEL_ID_BOTTOMMARGIN : ReadMargin(AStream, 3);
|
||||||
INT_EXCEL_ID_CODEPAGE : ReadCodePage(AStream);
|
INT_EXCEL_ID_CODEPAGE : ReadCodePage(AStream);
|
||||||
|
Reference in New Issue
Block a user