diff --git a/components/fpspreadsheet/source/common/fpsreaderwriter.pas b/components/fpspreadsheet/source/common/fpsreaderwriter.pas index e1c5f72c8..db22b8a38 100644 --- a/components/fpspreadsheet/source/common/fpsreaderwriter.pas +++ b/components/fpspreadsheet/source/common/fpsreaderwriter.pas @@ -364,7 +364,7 @@ end; class function TsCustomSpreadReader.CheckFileFormat(AStream: TStream): boolean; begin Unused(AStream); - Result := true; + Result := not HasZipHeader(AStream); end; {@@ ---------------------------------------------------------------------------- diff --git a/components/fpspreadsheet/source/common/fpsutils.pas b/components/fpspreadsheet/source/common/fpsutils.pas index bb8bfcf81..89bda3db1 100644 --- a/components/fpspreadsheet/source/common/fpsutils.pas +++ b/components/fpspreadsheet/source/common/fpsutils.pas @@ -212,6 +212,7 @@ procedure InitHeaderFooterImageRecord(out AImage: TsHeaderFooterImage); //procedure CopyCellValue(AFromCell, AToCell: PCell); function HasFormula(ACell: PCell): Boolean; function Has3dFormula(ACell: PCell): Boolean; +function HasZipHeader(AStream: TStream): Boolean; function SameCellBorders(AFormat1, AFormat2: PsCellFormat): Boolean; function SameFont(AFont1, AFont2: TsFont): Boolean; overload; function SameFont(AFont: TsFont; AFontName: String; AFontSize: Single; @@ -2552,6 +2553,29 @@ begin 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 @param AFormat1 Pointer to the first one of the two format records to be compared diff --git a/components/fpspreadsheet/source/common/fpsxmlcommon.pas b/components/fpspreadsheet/source/common/fpsxmlcommon.pas index c970c8465..8db007e5e 100644 --- a/components/fpspreadsheet/source/common/fpsxmlcommon.pas +++ b/components/fpspreadsheet/source/common/fpsxmlcommon.pas @@ -57,8 +57,6 @@ function CreateTempStream(AWorkbook: TsBasicWorkbook; AFileNameBase: String): TStream; procedure DestroyTempStream(AStream: TStream); -function HasZipHeader(AStream: TStream): Boolean; - implementation @@ -394,7 +392,6 @@ begin Result := TMemoryStream.Create; end; - procedure DestroyTempStream(AStream: TStream); var fn: String; @@ -412,26 +409,5 @@ begin 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.