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]);
|
||||
|
||||
// Here is the trial-and-error loop checking for the various formats.
|
||||
success := false;
|
||||
for i:=0 to High(fileformats) do begin
|
||||
try
|
||||
ReadFromFile(AFileName, fileformats[i], AParams);
|
||||
success := true;
|
||||
break; // Exit the loop if we reach this point successfully.
|
||||
except
|
||||
success := false;
|
||||
//success := false;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -574,6 +574,7 @@ var
|
||||
BIFF2EOF: Boolean;
|
||||
RecordType: Word;
|
||||
CurStreamPos: Int64;
|
||||
BOFFound: Boolean;
|
||||
begin
|
||||
Unused(AParams);
|
||||
BIFF2EOF := False;
|
||||
@ -582,6 +583,7 @@ begin
|
||||
FWorksheet := FWorkbook.AddWorksheet('Sheet', true);
|
||||
|
||||
{ Read all records in a loop }
|
||||
BOFFound := false;
|
||||
while not BIFF2EOF do
|
||||
begin
|
||||
{ Read the record header }
|
||||
@ -592,7 +594,7 @@ begin
|
||||
|
||||
case RecordType of
|
||||
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_BOTTOMMARGIN : ReadMargin(AStream, 3);
|
||||
INT_EXCEL_ID_CODEPAGE : ReadCodePage(AStream);
|
||||
@ -630,7 +632,11 @@ begin
|
||||
// Make sure we are in the right position for the next record
|
||||
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;
|
||||
|
||||
FixCols(FWorksheet);
|
||||
|
@ -957,11 +957,12 @@ begin
|
||||
try
|
||||
OLEDocument.Stream := OLEStream;
|
||||
OLEStorage.ReadOLEStream(AStream, OLEDocument, 'Workbook');
|
||||
InternalReadFromStream(OLEStream);
|
||||
finally
|
||||
OLEStorage.Free;
|
||||
end;
|
||||
|
||||
InternalReadFromStream(OLEStream);
|
||||
// InternalReadFromStream(OLEStream); // wp: moved up
|
||||
|
||||
finally
|
||||
OLEStream.Free;
|
||||
|
@ -971,43 +971,6 @@ end;
|
||||
procedure TsWorkbookSource.InternalLoadFromFile(AFileName: string;
|
||||
AAutoDetect: Boolean; AFormatID: TsSpreadFormatID;
|
||||
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
|
||||
book: TsWorkbook;
|
||||
begin
|
||||
@ -1018,51 +981,13 @@ begin
|
||||
book.ReadfromFile(AFileName)
|
||||
else
|
||||
book.ReadFromFile(AFileName, AFormatID);
|
||||
InternalLoadFromWorkbook(book, AWorksheetIndex);
|
||||
except
|
||||
book.AddErrorMsg(rsCannotReadFile, [AFileName]);
|
||||
// Code executed subsequently will be a pain if there is no worksheet! --> Add one.
|
||||
if book.GetWorksheetCount = 0 then
|
||||
book.AddWorksheet(Format(rsDefaultSheetName, [1]));
|
||||
// book is normally used as current workbook. But it must be destroyed
|
||||
// if the file cannot be read.
|
||||
book.Free;
|
||||
raise;
|
||||
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;
|
||||
|
||||
procedure TsWorkbookSource.InternalLoadFromWorkbook(AWorkbook: TsWorkbook;
|
||||
|
Reference in New Issue
Block a user