You've already forked lazarus-ccr
fpspreadsheet: Fix loading error messages not being shown by TsWorkbookSource.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5606 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -8058,13 +8058,14 @@ begin
|
|||||||
raise Exception.CreateFmt(rsReaderNotFound, [AFileName]);
|
raise Exception.CreateFmt(rsReaderNotFound, [AFileName]);
|
||||||
|
|
||||||
// Here is the trial-and-error loop checking for the various formats.
|
// Here is the trial-and-error loop checking for the various formats.
|
||||||
|
success := false;
|
||||||
for i:=0 to High(fileformats) do begin
|
for i:=0 to High(fileformats) do begin
|
||||||
try
|
try
|
||||||
ReadFromFile(AFileName, fileformats[i], AParams);
|
ReadFromFile(AFileName, fileformats[i], AParams);
|
||||||
success := true;
|
success := true;
|
||||||
break; // Exit the loop if we reach this point successfully.
|
break; // Exit the loop if we reach this point successfully.
|
||||||
except
|
except
|
||||||
success := false;
|
//success := false;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -574,6 +574,7 @@ var
|
|||||||
BIFF2EOF: Boolean;
|
BIFF2EOF: Boolean;
|
||||||
RecordType: Word;
|
RecordType: Word;
|
||||||
CurStreamPos: Int64;
|
CurStreamPos: Int64;
|
||||||
|
BOFFound: Boolean;
|
||||||
begin
|
begin
|
||||||
Unused(AParams);
|
Unused(AParams);
|
||||||
BIFF2EOF := False;
|
BIFF2EOF := False;
|
||||||
@ -582,6 +583,7 @@ begin
|
|||||||
FWorksheet := FWorkbook.AddWorksheet('Sheet', true);
|
FWorksheet := FWorkbook.AddWorksheet('Sheet', true);
|
||||||
|
|
||||||
{ Read all records in a loop }
|
{ Read all records in a loop }
|
||||||
|
BOFFound := false;
|
||||||
while not BIFF2EOF do
|
while not BIFF2EOF do
|
||||||
begin
|
begin
|
||||||
{ Read the record header }
|
{ Read the record header }
|
||||||
@ -592,7 +594,7 @@ begin
|
|||||||
|
|
||||||
case RecordType of
|
case RecordType of
|
||||||
INT_EXCEL_ID_BLANK : ReadBlank(AStream);
|
INT_EXCEL_ID_BLANK : ReadBlank(AStream);
|
||||||
INT_EXCEL_ID_BOF : ;
|
INT_EXCEL_ID_BOF : BOFFound := true;
|
||||||
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);
|
||||||
@ -630,7 +632,11 @@ begin
|
|||||||
// Make sure we are in the right position for the next record
|
// Make sure we are in the right position for the next record
|
||||||
AStream.Seek(CurStreamPos + RecordSize, soFromBeginning);
|
AStream.Seek(CurStreamPos + RecordSize, soFromBeginning);
|
||||||
|
|
||||||
if AStream.Position >= AStream.Size then BIFF2EOF := True;
|
if AStream.Position >= AStream.Size then
|
||||||
|
BIFF2EOF := True;
|
||||||
|
|
||||||
|
if not BOFFound then
|
||||||
|
raise Exception.Create('BOF record not found.');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
FixCols(FWorksheet);
|
FixCols(FWorksheet);
|
||||||
|
@ -957,11 +957,12 @@ begin
|
|||||||
try
|
try
|
||||||
OLEDocument.Stream := OLEStream;
|
OLEDocument.Stream := OLEStream;
|
||||||
OLEStorage.ReadOLEStream(AStream, OLEDocument, 'Workbook');
|
OLEStorage.ReadOLEStream(AStream, OLEDocument, 'Workbook');
|
||||||
|
InternalReadFromStream(OLEStream);
|
||||||
finally
|
finally
|
||||||
OLEStorage.Free;
|
OLEStorage.Free;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
InternalReadFromStream(OLEStream);
|
// InternalReadFromStream(OLEStream); // wp: moved up
|
||||||
|
|
||||||
finally
|
finally
|
||||||
OLEStream.Free;
|
OLEStream.Free;
|
||||||
|
@ -971,43 +971,6 @@ end;
|
|||||||
procedure TsWorkbookSource.InternalLoadFromFile(AFileName: string;
|
procedure TsWorkbookSource.InternalLoadFromFile(AFileName: string;
|
||||||
AAutoDetect: Boolean; AFormatID: TsSpreadFormatID;
|
AAutoDetect: Boolean; AFormatID: TsSpreadFormatID;
|
||||||
AWorksheetIndex: Integer = -1);
|
AWorksheetIndex: Integer = -1);
|
||||||
{
|
|
||||||
// this version avoids loading a defective workbook into the grid,
|
|
||||||
// but tabcontrol navigation is not working here...
|
|
||||||
|
|
||||||
var
|
|
||||||
book: TsWorkbook;
|
|
||||||
begin
|
|
||||||
book := TsWorkbook.Create;
|
|
||||||
try
|
|
||||||
if AAutoDetect then
|
|
||||||
book.ReadFromFile(AFileName)
|
|
||||||
else
|
|
||||||
book.ReadFromFile(AFileName, AFormatID);
|
|
||||||
|
|
||||||
InternalCreateNewWorkbook(book); // book --> FWorkbook
|
|
||||||
except
|
|
||||||
book.Free;
|
|
||||||
InternalCreateNewWorkbook;
|
|
||||||
// --> empty workbook, but avoid having no worksheet
|
|
||||||
FWorksheet := FWorkbook.AddWorksheet(Format(rsDefaultSheetName, [1]));
|
|
||||||
DoShowError(Format(rsCannotReadFile, [AFileName]));
|
|
||||||
end;
|
|
||||||
|
|
||||||
if AWorksheetIndex = -1 then
|
|
||||||
begin
|
|
||||||
if FWorkbook.ActiveWorksheet <> nil then
|
|
||||||
AWorksheetIndex := FWorkbook.GetWorksheetIndex(FWorkbook.ActiveWorksheet) else
|
|
||||||
AWorksheetIndex := 0;
|
|
||||||
end;
|
|
||||||
|
|
||||||
SelectWorksheet(FWorkbook.GetWorkSheetByIndex(AWorksheetIndex));
|
|
||||||
|
|
||||||
// If required, display loading error message
|
|
||||||
if FWorkbook.ErrorMsg <> '' then
|
|
||||||
DoShowError(FWorkbook.ErrorMsg);
|
|
||||||
end;
|
|
||||||
}
|
|
||||||
var
|
var
|
||||||
book: TsWorkbook;
|
book: TsWorkbook;
|
||||||
begin
|
begin
|
||||||
@ -1018,51 +981,13 @@ begin
|
|||||||
book.ReadfromFile(AFileName)
|
book.ReadfromFile(AFileName)
|
||||||
else
|
else
|
||||||
book.ReadFromFile(AFileName, AFormatID);
|
book.ReadFromFile(AFileName, AFormatID);
|
||||||
|
InternalLoadFromWorkbook(book, AWorksheetIndex);
|
||||||
except
|
except
|
||||||
book.AddErrorMsg(rsCannotReadFile, [AFileName]);
|
// book is normally used as current workbook. But it must be destroyed
|
||||||
// Code executed subsequently will be a pain if there is no worksheet! --> Add one.
|
// if the file cannot be read.
|
||||||
if book.GetWorksheetCount = 0 then
|
book.Free;
|
||||||
book.AddWorksheet(Format(rsDefaultSheetName, [1]));
|
raise;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
InternalLoadFromWorkbook(book, AWorksheetIndex);
|
|
||||||
|
|
||||||
(*
|
|
||||||
|
|
||||||
|
|
||||||
// Create a new empty workbook
|
|
||||||
InternalCreateNewWorkbook;
|
|
||||||
|
|
||||||
DisableControls;
|
|
||||||
try
|
|
||||||
// Read workbook from file and get worksheet
|
|
||||||
try
|
|
||||||
if AAutoDetect then
|
|
||||||
FWorkbook.ReadFromFile(AFileName)
|
|
||||||
else
|
|
||||||
FWorkbook.ReadFromFile(AFileName, AFormatID);
|
|
||||||
except
|
|
||||||
FWorkbook.AddErrorMsg(rsCannotReadFile, [AFileName]);
|
|
||||||
// Code executed subsequently will be a pain if there is no worksheet!
|
|
||||||
if FWorkbook.GetWorksheetCount = 0 then
|
|
||||||
FWorkbook.AddWorksheet(Format(rsDefaultSheetName, [1]));
|
|
||||||
end;
|
|
||||||
finally
|
|
||||||
EnableControls;
|
|
||||||
end;
|
|
||||||
|
|
||||||
if AWorksheetIndex = -1 then
|
|
||||||
begin
|
|
||||||
if FWorkbook.ActiveWorksheet <> nil then
|
|
||||||
AWorksheetIndex := FWorkbook.GetWorksheetIndex(FWorkbook.ActiveWorksheet) else
|
|
||||||
AWorksheetIndex := 0;
|
|
||||||
end;
|
|
||||||
SelectWorksheet(FWorkbook.GetWorkSheetByIndex(AWorksheetIndex));
|
|
||||||
|
|
||||||
// If required, display loading error message
|
|
||||||
if FWorkbook.ErrorMsg <> '' then
|
|
||||||
DoShowError(FWorkbook.ErrorMsg);
|
|
||||||
*)
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TsWorkbookSource.InternalLoadFromWorkbook(AWorkbook: TsWorkbook;
|
procedure TsWorkbookSource.InternalLoadFromWorkbook(AWorkbook: TsWorkbook;
|
||||||
|
Reference in New Issue
Block a user