Recent

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

franzala

  • New Member
  • *
  • Posts: 15
Can't read LibreOffice files .ods
« on: May 21, 2020, 11:00:36 pm »
With Lazarus 1.8.2    FPC 3.0.4 and FPSpreadsheet 1.10.1 I can't read .ods files neither with the unit fpsopendocument in the uses clause, which gives the message unsupported file format
nor with the unit fpsallformats which tries to open an xlsx file and finds a defective structure.

xlsx files are opened without problem.

Did I miss something?


wp

  • Hero Member
  • *****
  • Posts: 7081
Re: Can't read LibreOffice files .ods
« Reply #1 on: May 21, 2020, 11:25:02 pm »
Please show your code.

And is it really an ODS file? Rename the ODS file to ZIP and extract its contents to some temp directory, you should see xml files such as "content.xml", "styles.xml" etc. If you cannot do this or if you do not get these files it is not an ODS file. If everything works you should upload the file to the forum (or to some cloud space and send me the link by PM) so that I can have a closer look.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

franzala

  • New Member
  • *
  • Posts: 15
Re: Can't read LibreOffice files .ods
« Reply #2 on: May 22, 2020, 02:18:52 pm »
My ods file was created with LibreOffice, consequently I consider it as a genuine ods file (but maybe it's wrong).

While preparing my answer,I tried to continue despite the error message and was surprised to see that the few lines of my test code seem to work properly: the different variables contain the correct value.

I attached the complete unit of my code and an ods file created with LibreOffice which generates the error message when I debug. When I save that file with LibreOffice (under Ubuntu 18.04.4 LTS) as xlsx file and change the uses clause, I do not have any error message.

PS: due to the restrictions in allowed formats, I zipped both file

wp

  • Hero Member
  • *****
  • Posts: 7081
Re: Can't read LibreOffice files .ods
« Reply #3 on: May 22, 2020, 02:30:43 pm »
Sorry - the attachment contains only empty directories.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

straetch

  • Jr. Member
  • **
  • Posts: 63
Re: Can't read LibreOffice files .ods
« Reply #4 on: May 22, 2020, 04:27:17 pm »
I have the same problem.

When I open a .ods file, created by Libreoffice, I get a Debugger Exception Notification with the message:
Project ... raised exception class 'EFpSpreadsheetReader' with message
Defective internal structure of xlsx file in file 'source\common\xlsxooml.pas' at line 2538.

As per your earlier post, I changed the extension of the .ods file to .zip and I see the files content.xml, settings.xml , styles.xml etc.

Using Lazarus 2.0.6 and fpspreadsheet 1.10.1

franzala

  • New Member
  • *
  • Posts: 15
Re: Can't read LibreOffice files .ods
« Reply #5 on: May 22, 2020, 05:03:53 pm »
My mistake, sorry.  Attached is a hopefully better zip file.

franzala

  • New Member
  • *
  • Posts: 15
Re: Can't read LibreOffice files .ods
« Reply #6 on: May 22, 2020, 05:28:03 pm »
Just a detail, with the unit fpsopendocument in the uses clause, the EFPSpreadsheetReader error message is slightly different: tried to read spreadsheet using unsupported format, but the result seems to be the same.

straetch

  • Jr. Member
  • **
  • Posts: 63
Re: Can't read LibreOffice files .ods
« Reply #7 on: May 22, 2020, 05:49:49 pm »
As an addition:
With the version of fpspreadsheet I used before (I dont'n know anymore which version number), I did not have this problem. It is only with recompiling the unchanged program with version 1.10.1 that the problem came up.

wp

  • Hero Member
  • *****
  • Posts: 7081
Re: Can't read LibreOffice files .ods
« Reply #8 on: May 22, 2020, 06:29:29 pm »
Ok I understand now. This is an exception which occurs during format detection only when the IDE is running, it does not occur when you run your exe outside the IDE (or with "Run" > "Run without debugger").

Let me explain: Your code "wb1.ReadFromFile(OD1.FileName)" does not contain a specification of the file format. Therefore fpspreadsheet tries to detect the format automatically. In a first step it reads the first few bytes from the file and tries to identify the format from the file header. File formats which cannot be identified from the header are opened for testing, and an exception is raised when the format does not match. This exception is what you are seeing. It is handled immediately and silently by the reader so that testing can proceed with the next format.

This reading procedure has been changed in the current trunk version of fpspreadsheet already some time ago, and the exception does not occur here. Unfortunately the new features have not been released yet (because I had began adding chart support, which maybe was not a good idea...).

So, in your version, you can safely ignore this exception. I am not 100% sure but you could try to add the exception type EFpSpreadSheetReader to the ignore list of the project (in v1.8.2 this is in "Tools" > "Options" > "Debugger > "Language Exceptions"", now it is in "Project" > "Options" > "Language Exceptions").

Alternatively you can avoid the exception when you specify the format in the ReadFromFile call: "wb1.ReadFromFile(OD1.FileName, sfOpenDocument)".

------------

In very old fpspreadsheet versions this exception did not occur because file formats were handled differently. This was changed to allow for user-defined spreadsheet format.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

straetch

  • Jr. Member
  • **
  • Posts: 63
Re: Can't read LibreOffice files .ods
« Reply #9 on: May 23, 2020, 08:59:01 am »
Thanks for the prompt reply.
Let me see if I get it right.

In the error message "Debugger Exception Notification" form, there is a checkbox "Ignore this exception type". I could check this and click on Continue. Will the automatic format detection then still work, since the reader uses the exception to work correctly?

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?
Is there a patch I can use to overwrite the reader?


wp

  • Hero Member
  • *****
  • Posts: 7081
Re: Can't read LibreOffice files .ods
« Reply #10 on: May 23, 2020, 10:28:25 am »
In the error message "Debugger Exception Notification" form, there is a checkbox "Ignore this exception type". I could check this and click on Continue. Will the automatic format detection then still work, since the reader uses the exception to work correctly?
Yes this should work. It certainly will not affect automatic format detection.

I can live with for some time until you make a new official release of fpspreadsheet. Any idea when?
I don't know. I had begun implementing chart support already some time ago, but gut stuck due to the immense amount of data needed in the files for them, and I lost interest in the subject. I don't want to have an incomplete feature in the library. So, maybe I should undo the related changes?

Is there a patch I can use to overwrite the reader?
IIRC there were too many related changes.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

lucamar

  • Hero Member
  • *****
  • Posts: 2856
Re: Can't read LibreOffice files .ods
« Reply #11 on: May 23, 2020, 10:52:54 am »
In the error message "Debugger Exception Notification" form, there is a checkbox "Ignore this exception type". I could check this and click on Continue. Will the automatic format detection then still work, since the reader uses the exception to work correctly?

Yes, if you check "Ignore this exception type" you'll not be bothered by them anymore, but if you don't want to ever see them again go to "Tools->Options->Debugger" and add it to the list of ignored exceptions (see atached image).
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

wp

  • Hero Member
  • *****
  • Posts: 7081
Re: Can't read LibreOffice files .ods
« Reply #12 on: May 23, 2020, 10:55:31 am »
In the error message "Debugger Exception Notification" form, there is a checkbox "Ignore this exception type". I could check this and click on Continue. Will the automatic format detection then still work, since the reader uses the exception to work correctly?

Yes, if you check "Ignore this exception type" you'll not be bothered by them anymore, but if you don't want to ever see them again go to "Tools->Options->Debugger" and add it to the list of ignored exceptions (see atached image).
To my knowledge it is project-specific. Having this option in the IDE options was misleading and this is why it was moved to the project options in trunk.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

lucamar

  • Hero Member
  • *****
  • Posts: 2856
Re: Can't read LibreOffice files .ods
« Reply #13 on: May 23, 2020, 11:11:58 am »
To my knowledge it is project-specific. Having this option in the IDE options was misleading and this is why it was moved to the project options in trunk.

Yes, it says it right there: "These settings are stored with the project". I wrote: "(for the current project)" in my answer but it has somehow dissapeared (a "cut/forgot-to-paste" problem) :-[
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

franzala

  • New Member
  • *
  • Posts: 15
Re: Can't read LibreOffice files .ods
« Reply #14 on: May 23, 2020, 12:26:54 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.

I'd preferred use open source solutions, but I hope it will be a temporary exception.

As far as I'm concerned, this topic could be considered as solved.


 

TinyPortal © 2005-2018