OpenOffice Writer - software update tables with cell formulas

I am really stuck trying to figure out how to force a software update on openoffice writer cell calculations (3.3) when cell values โ€‹โ€‹are bookmarks and bookmarks are updated programmatically (via UNO calls in Java).

Example

| start | stop | duration | | 9:30 | 11:30 | = <A2>-<B2> | <= cell formula 

This works great when the user manually edits the table, the value is updated when they move to the next cell. However, if I programmatically update values โ€‹โ€‹by inserting text into bookmarks in cells, the calculated cells are not updated. They will be updated if you click in the table, but I would like it to be automatic.

The bookmark is in the table as follows.

 | start | stop | duration | | <start0> | <stop0> | = <A2>-<B2> | 

Sample code for updating a bookmark:

 XBookmarksSupplier xBookmarksSupplier = (XBookmarksSupplier) UnoRuntime.queryInterface(XBookmarksSupplier.class, document); XNameAccess xNamedBookmarks = xBookmarksSupplier.getBookmarks(); Object bookmark = xNamedBookmarks.getByName("stop0"); XTextContent xBookmarkContent = (XTextContent) UnoRuntime.queryInterface(XTextContent.class, bookmark); xBookmarkContent.getAnchor().setString("11:30"); // code needed to force calculation of duration cell 
+4
source share
1 answer

I realized that myself. The key is to use XRefreshable and know that the cell formulas in the tables are considered โ€œtext fieldsโ€ - therefore, using the traditional long (but fun) UNO meta-programming style ...

  • request provider text fields from an XTextDocument instance
  • request for an updated instance from an enumeration of text fields
  • refresh call

Update: this will not work if the source cells in the updated formula have the format applied to them, the format of the destination cell does not matter.

the code

 XTextFieldsSupplier tfSupplier = (XTextFieldsSupplier) UnoRuntime.queryInterface(XTextFieldsSupplier.class, document); XRefreshable refreshable = (XRefreshable) UnoRuntime.queryInterface(XRefreshable.class, tfSupplier.getTextFields()); refreshable.refresh(); 
+3
source

Source: https://habr.com/ru/post/1402633/


All Articles