Recent

Author Topic: Can't read LibreOffice files .ods  (Read 3941 times)

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Can't read LibreOffice files .ods
« Reply #15 on: May 23, 2020, 12:58:44 pm »
Thanks for your replies and help.

Since Libre and OpenOffice are able to save and read files under xlsx format, which has apparently no problem with FRSpreadsheet, I think I will consider to use that file format instead of ods (provided there are no problematical format conversion restrictions, which I will have to check).

I don't like too much to ignore an error message which eventually could be raised by other problems than the one we try to solve.
But for the other cases which are not handled by the library you will still see the error message displayed by the application (the one you see is displayed by the debugger). In this (rare) case you still can reactivate the debugger exception to make the program stop when the exception occurs.

I hope it will be a temporary exception.
I don't think so. Raising an exception when a file cannot be read is the ultimate notification of the user, and it will always be there.

But let me say again: You can avoid the exception when you specify the format in the ReadFromFile call. So when you know that your files are .ods, then why don't you specify the format directly instead of (ab)using automatic format detection?

And another solution which has not been mentioned before: You could also switch your fpspreadsheet to the trunk version in which format detection is a bit more sophisticated. Just download the snapshot from https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/components/fpspreadsheet/.

straetch

  • Jr. Member
  • **
  • Posts: 75
Re: Can't read LibreOffice files .ods
« Reply #16 on: May 24, 2020, 10:51:56 am »
In my case the automatic format detection is necessary. My program collects spreadsheets from different authors that can provide their data in different formats (xls, xlsx, ods, csv).
I have set "ignore this exception type" at project level.
I don't worry about this because the exception class 'EFpSpreadsheetReader' is defined in the fpspreadsheet package.
Since the author of the package says there is no problem with this, why should I doubt this?
I am happy with the temporary solution.
Many thanks.

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Can't read LibreOffice files .ods
« Reply #17 on: June 03, 2020, 11:21:45 am »
Knowing this, it is a minor nuisance that I can live with for some time until you make a new official release of fpspreadsheet. Any idea when?
A new version 1.12 has been released yesterday, it is available via OPM.

franzala

  • New Member
  • *
  • Posts: 39
Re: Can't read LibreOffice files .ods
« Reply #18 on: June 05, 2020, 07:34:01 pm »
I have tried the version 1.12 with a short test code;that new version works fine and and  is able to read the Libre/OpenOffice ods fileformat with and without specifying the fileformat in the procedure ReadFromFile.

But I have now a problem with an older application which I used with xlsx files; I obtain now the following error message on debuging :
operator is not overloaded : - ''TSWorkbook''

Any idea about what could cause that error message?




wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Can't read LibreOffice files .ods
« Reply #19 on: June 05, 2020, 07:41:33 pm »
Please show more code

franzala

  • New Member
  • *
  • Posts: 39
Re: Can't read LibreOffice files .ods
« Reply #20 on: June 05, 2020, 10:03:50 pm »
I have cut everything except the procedure where the error arrises and checked that the error message remains; it is the case with the following code:
.
procedure TFocpta1g.MFiOuvClick(Sender: TObject);       //M Fichier Ouvrir
begin
  OD1.Title:='fichier ... format ods  ';
  OD1.Filter:='fichier ods|*.ods';
  if OD1.Execute then
    ficpta:=OD1.FileName;-
  wb1:=TsWorkbook.Create;
  wb1.ReadFromFile(ficpta,sfOpenDocument);
  ws1:=wb1.GetWorksheetByName('Param');
end;

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Can't read LibreOffice files .ods
« Reply #21 on: June 05, 2020, 10:32:39 pm »
Probably the '-' at the end of the line "ficpta := OD1.FileName;-".

Another issue is that a workbook is created although the OpenDialog has been aborted; a begin-end block is missing after the "if" downto the "end":
Code: Pascal  [Select][+][-]
  1. procedure TFocpta1g.MFiOuvClick(Sender: TObject);       //M Fichier Ouvrir
  2. begin
  3.   OD1.Title:='fichier ... format ods  ';
  4.   OD1.Filter:='fichier ods|*.ods';
  5.   if OD1.Execute then
  6.   begin                       // <------ "begin" added to execute everything when the OpenDialog has been closed successfully.
  7.     ficpta:=OD1.FileName;     // <---- remove the '-' at the end of the line
  8.     wb1:=TsWorkbook.Create;
  9.     wb1.ReadFromFile(ficpta,sfOpenDocument);
  10.     ws1:=wb1.GetWorksheetByName('Param');
  11.   end;                        // <-------- "end" added
  12. end;

 

TinyPortal © 2005-2018