当单元格值为书签并且书签以编程方式更新(通过 Java 中的 UNO 调用)时,我真的很想找出如何强制以编程方式刷新 openoffice writer (3.3) 单元格计算。
Example
| start | stop | duration |
| 9:30 | 11:30 | = <A2>-<B2> | <= cell formula
当用户手动编辑表格时,这可以正常工作,当他们移动到下一个单元格时,该值会更新。但是,如果我通过将文本插入单元格中的书签以编程方式更新值,则计算的单元格不会更新。如果您单击表格,它们就会更新,但我希望这是自动的。
书签在表格中是这样的。
| start | stop | duration |
| <start0> | <stop0> | = <A2>-<B2> |
更新书签的示例代码:
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
我自己已经弄清楚了。关键是要使用X可刷新 http://www.openoffice.org/api/docs/common/ref/com/sun/star/util/XRefreshable.html并且知道表格中的单元格公式算作“文本字段” - 因此使用传统的冗长(但有趣)UNO 元编程风格......
- 从 XTextDocument 实例查询文本字段供应商
- 从文本字段枚举查询可刷新实例
- 呼叫刷新
更新:如果正在更新的公式中的源单元格应用了格式,则此操作将不起作用,目标单元格的格式并不重要。
Code
XTextFieldsSupplier tfSupplier = (XTextFieldsSupplier)
UnoRuntime.queryInterface(XTextFieldsSupplier.class, document);
XRefreshable refreshable = (XRefreshable)
UnoRuntime.queryInterface(XRefreshable.class, tfSupplier.getTextFields());
refreshable.refresh();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)