You've already forked lazarus-ccr
fpspreadsheet: Avoid format detection pick csv reader when fpsAllFormats is used and the provided xlsx file contains an error.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6820 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -364,7 +364,7 @@ end;
|
|||||||
class function TsCustomSpreadReader.CheckFileFormat(AStream: TStream): boolean;
|
class function TsCustomSpreadReader.CheckFileFormat(AStream: TStream): boolean;
|
||||||
begin
|
begin
|
||||||
Unused(AStream);
|
Unused(AStream);
|
||||||
Result := true;
|
Result := not HasZipHeader(AStream);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
|
@ -212,6 +212,7 @@ procedure InitHeaderFooterImageRecord(out AImage: TsHeaderFooterImage);
|
|||||||
//procedure CopyCellValue(AFromCell, AToCell: PCell);
|
//procedure CopyCellValue(AFromCell, AToCell: PCell);
|
||||||
function HasFormula(ACell: PCell): Boolean;
|
function HasFormula(ACell: PCell): Boolean;
|
||||||
function Has3dFormula(ACell: PCell): Boolean;
|
function Has3dFormula(ACell: PCell): Boolean;
|
||||||
|
function HasZipHeader(AStream: TStream): Boolean;
|
||||||
function SameCellBorders(AFormat1, AFormat2: PsCellFormat): Boolean;
|
function SameCellBorders(AFormat1, AFormat2: PsCellFormat): Boolean;
|
||||||
function SameFont(AFont1, AFont2: TsFont): Boolean; overload;
|
function SameFont(AFont1, AFont2: TsFont): Boolean; overload;
|
||||||
function SameFont(AFont: TsFont; AFontName: String; AFontSize: Single;
|
function SameFont(AFont: TsFont; AFontName: String; AFontSize: Single;
|
||||||
@ -2552,6 +2553,29 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
|
Returns true if the file begins with a ZIP header *PK'#03#04.
|
||||||
|
Needed for file format detection.
|
||||||
|
-------------------------------------------------------------------------------}
|
||||||
|
function HasZipHeader(AStream: TStream): Boolean;
|
||||||
|
const
|
||||||
|
ZIP_HEADER: packed array[0..3] of char = ('P', 'K', #03, #04);
|
||||||
|
var
|
||||||
|
P: Int64;
|
||||||
|
buf: packed array[0..3] of char = (#0, #0, #0, #0);
|
||||||
|
begin
|
||||||
|
Result := false;
|
||||||
|
P := AStream.Position;
|
||||||
|
try
|
||||||
|
AStream.Position := 0;
|
||||||
|
if AStream.Read(buf, 4) < 4 then
|
||||||
|
exit;
|
||||||
|
Result := CompareMem(@buf[0], @ZIP_HEADER[0], 4);
|
||||||
|
finally
|
||||||
|
AStream.Position := P;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{-------------------------------------------------------------------------------
|
||||||
Checks whether two format records have same border attributes
|
Checks whether two format records have same border attributes
|
||||||
|
|
||||||
@param AFormat1 Pointer to the first one of the two format records to be compared
|
@param AFormat1 Pointer to the first one of the two format records to be compared
|
||||||
|
@ -57,8 +57,6 @@ function CreateTempStream(AWorkbook: TsBasicWorkbook;
|
|||||||
AFileNameBase: String): TStream;
|
AFileNameBase: String): TStream;
|
||||||
procedure DestroyTempStream(AStream: TStream);
|
procedure DestroyTempStream(AStream: TStream);
|
||||||
|
|
||||||
function HasZipHeader(AStream: TStream): Boolean;
|
|
||||||
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
@ -394,7 +392,6 @@ begin
|
|||||||
Result := TMemoryStream.Create;
|
Result := TMemoryStream.Create;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure DestroyTempStream(AStream: TStream);
|
procedure DestroyTempStream(AStream: TStream);
|
||||||
var
|
var
|
||||||
fn: String;
|
fn: String;
|
||||||
@ -412,26 +409,5 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
{ Returns true if the file begins with a ZIP header *PK'. Needed for
|
|
||||||
file format detection. }
|
|
||||||
function HasZipHeader(AStream: TStream): Boolean;
|
|
||||||
const
|
|
||||||
ZIP_HEADER: packed array[0..1] of char = ('P', 'K');
|
|
||||||
var
|
|
||||||
P: Int64;
|
|
||||||
buf: packed array[0..1] of char = (#0, #0);
|
|
||||||
begin
|
|
||||||
Result := false;
|
|
||||||
P := AStream.Position;
|
|
||||||
try
|
|
||||||
AStream.Position := 0;
|
|
||||||
if AStream.Read(buf, 2) < 2 then
|
|
||||||
exit;
|
|
||||||
Result := (buf[0] = ZIP_HEADER[0]) and (buf[1] = ZIP_HEADER[1]);
|
|
||||||
finally
|
|
||||||
AStream.Position := P;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user