I need to read excel files created by attendance machine.
When I open the file in MsOffice, the file's property says it is an Excel2 format.
When I try to open the file with autodetection
wb.ReadFromFile(Self.OpenDialog1.FileName{,sfExcel2});
The autodetection mechanism shows a XMLReadError which is eaten than, and then it fails to read the file.
If I open the file with specific version of Excel2
wb.ReadFromFile(Self.OpenDialog1.FileName,sfExcel2);
it throws a EFpSpreadsheetReader exception with message BOF record not found.
Is fpSpreadsheet not able to read old excel 2 files?
Here is the full code
procedure TForm1.Button1Click(Sender: TObject);
var
wb:TsWorkbook;
ws:TsWorksheet;
ptrCell:PCell;
str:String;
begin
wb:=TsWorkbook.Create;
try
Self.OpenDialog1.Filter:='Excel file|*.xls;*.xlsx';
if Self.OpenDialog1.Execute then begin
wb.ReadFromFile(Self.OpenDialog1.FileName,sfExcel2);
ws:=wb.GetFirstWorksheet;
ptrCell:=ws.GetCell(0,0);
str:=ptrCell^.UTF8StringValue;
ShowMessage( 'Cell A1 contains "' + str + '"');
end;
finally
wb.Free;
end;
end;
Environment:
O/S: Linux 64bit
FPC:3.2.2
Lazarus:2.2.5
fpSpreadsheet:1.14.0.0 (installed with OPM)
Thank you for the help.
Best regards,
Bambang
Attached is the simple demo project.
The link to download the excel file from my google drive is in the unit1.pas