You've already forked lazarus-ccr
fpspreadsheet: Improved file format detection
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3905 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -964,7 +964,7 @@ implementation
|
||||
|
||||
uses
|
||||
Math, StrUtils, TypInfo, lazutf8,
|
||||
fpsPatches, fpsStrings, fpsStreams,
|
||||
fpsPatches, fpsStrings, fpsStreams, uvirtuallayer_ole,
|
||||
fpsUtils, fpsCurrency, fpsNumFormatParser, fpsExprParser;
|
||||
|
||||
const
|
||||
@ -6434,18 +6434,27 @@ const
|
||||
$09,$00, $04,$00, $00,$00, $10,$00, $31,$00, $0A,$00, $C8,$00, $00,$00);
|
||||
BIFF58_HEADER: array[0..7] of byte = (
|
||||
$D0,$CF, $11,$E0, $A1,$B1, $1A,$E1);
|
||||
BIFF5_MARKER: array[0..7] of widechar = (
|
||||
'B', 'o', 'o', 'k', #0, #0, #0, #0);
|
||||
BIFF8_MARKER:array[0..7] of widechar = (
|
||||
'W', 'o', 'r', 'k', 'b', 'o', 'o', 'k');
|
||||
|
||||
function ValidOLEStream(AStream: TStream; AName: String): Boolean;
|
||||
var
|
||||
fsOLE: TVirtualLayer_OLE;
|
||||
begin
|
||||
AStream.Position := 0;
|
||||
fsOLE := TVirtualLayer_OLE.Create(AStream);
|
||||
try
|
||||
fsOLE.Initialize;
|
||||
Result := fsOLE.FileExists('/'+AName);
|
||||
finally
|
||||
fsOLE.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
var
|
||||
buf: packed array[0..16] of byte;
|
||||
buf: packed array[0..16] of byte = (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
|
||||
stream: TStream;
|
||||
i: Integer;
|
||||
ok: Boolean;
|
||||
begin
|
||||
buf[0] := 0; // Silence the compiler...
|
||||
|
||||
Result := false;
|
||||
stream := TFileStream.Create(AFileName, fmOpenRead + fmShareDenyNone);
|
||||
try
|
||||
@ -6471,28 +6480,20 @@ begin
|
||||
if buf[i] <> BIFF58_HEADER[i] then
|
||||
exit;
|
||||
|
||||
// Further information begins at offset $480:
|
||||
stream.Position := $480;
|
||||
stream.ReadBuffer(buf, 16);
|
||||
// Check for Excel5
|
||||
ok := true;
|
||||
for i:=0 to 7 do
|
||||
if WideChar(buf[i*2]) <> BIFF5_MARKER[i] then
|
||||
begin
|
||||
ok := false;
|
||||
break;
|
||||
end;
|
||||
if ok then
|
||||
begin
|
||||
// Now we know that the file is a Microsoft compound document.
|
||||
|
||||
// We check for Excel 5 in which the stream is named "Book"
|
||||
if ValidOLEStream(stream, 'Book') then begin
|
||||
SheetType := sfExcel5;
|
||||
Exit(True);
|
||||
exit(True);
|
||||
end;
|
||||
// Check for Excel8
|
||||
for i:=0 to 7 do
|
||||
if WideChar(buf[i*2]) <> BIFF8_MARKER[i] then
|
||||
exit(false);
|
||||
SheetType := sfExcel8;
|
||||
Exit(True);
|
||||
|
||||
// Now we check for Excel 8 which names the stream "Workbook"
|
||||
if ValidOLEStream(stream, 'Workbook') then begin
|
||||
SheetType := sfExcel8;
|
||||
exit(True);
|
||||
end;
|
||||
|
||||
finally
|
||||
stream.Free;
|
||||
end;
|
||||
@ -8447,17 +8448,10 @@ procedure TsCustomSpreadReader.ReadFromFile(AFileName: string; AData: TsWorkbook
|
||||
var
|
||||
InputFile: TStream;
|
||||
begin
|
||||
|
||||
if (boBufStream in Workbook.Options) then
|
||||
InputFile := TBufStream.Create(AFileName, fmOpenRead + fmShareDenyNone)
|
||||
else
|
||||
InputFile := TFileStream.Create(AFileName, fmOpenRead + fmShareDenyNone);
|
||||
{
|
||||
//<--
|
||||
InputFile := TMemoryStream.Create;
|
||||
TMemoryStream(InputFile).LoadFromFile(AFilename);
|
||||
//--->
|
||||
}
|
||||
|
||||
try
|
||||
ReadFromStream(InputFile, AData);
|
||||
|
@ -27,6 +27,7 @@ type
|
||||
function FindMounted(const APath: UTF8String): TVirtualLayer; overload;
|
||||
function PreviousPath(const APath: UTF8String): UTF8String;
|
||||
function StripMountPoints(const APath: UTF8String): UTF8String;
|
||||
|
||||
protected
|
||||
FParentLayer: TVirtualLayer;
|
||||
FVirtualLayerStream: TStream;
|
||||
@ -59,8 +60,8 @@ type
|
||||
|
||||
procedure Lock(); virtual;
|
||||
procedure Unlock(); virtual;
|
||||
public
|
||||
|
||||
public
|
||||
function MakeFolder(const AFolder: UTF8String): Boolean;
|
||||
function RemoveFolder(const AFolder: UTF8String): Boolean;
|
||||
function DeleteFile(const AFileName: UTF8String): Boolean;
|
||||
@ -100,11 +101,11 @@ type
|
||||
implementation
|
||||
|
||||
type
|
||||
TFileRecLocal=record
|
||||
FL: TVirtualLayer_FolderList;
|
||||
Attr: LongInt;
|
||||
end;
|
||||
PFileRecLocal=^TFileRecLocal;
|
||||
TFileRecLocal = record
|
||||
FL: TVirtualLayer_FolderList;
|
||||
Attr: LongInt;
|
||||
end;
|
||||
PFileRecLocal=^TFileRecLocal;
|
||||
|
||||
{ TVirtualLayer }
|
||||
|
||||
|
Reference in New Issue
Block a user