ODFToolkit - recalculate all formulas

437 views Asked by At

I have two files:

  • 1.ods in C:\
  • 2.ods in Z:\

In 1.ods - cell A1 I've typed 10, saved, closed.

In 2.ods - cell A1 I've typed formula: ='file:///Z:/1.ods'#$Sheet1.A1, saved, closed.

Now I want to recalculate value in 2.ods cell A1 programmatically using odftoolkit API when value in 1.ods cell A1 changes (after save of course).

There is a method for getting calculated value: Cell#getDisplayText but this is not working for external dependencies. I haven't found any API method that does the same thing as Open/LibreOffice shortcut Ctrl+Shift+F9.

How can I refresh/recalculate aforementioned value using only odftoolkit API?

(This is because I have 7000 ods files I don't want to recalculate manually and after that do what I need to do)

2

There are 2 answers

0
Xeon On BEST ANSWER

Looks like there is no functionality provided by the odftoolkit to do this as for now.

0
Ralph On

The ODF Toolkit is a lightweight Java library to create, read and update the data of ODF documents. Unlike other approaches, which rely on runtime manipulation of heavy-weight editors via an automation interface, you can only update the content of the (xml)document. But you have no access to any application interface like LibreOffice. So you can either calculate the results of your changes manually and update the corresponding cells or you use a recalculate functionality like Ctrl+Shift+F9 in LibreOffice to update all formulas after the document opens.

Note: If you update spreadSheet cells with the ODFToolkit by recalculating its values in the backend, your original formulas will remain intact. In this way changes, made later in an editor like LibreOffice or Collabora, are automatically recalculated by your origin formulas.