我正在努力理解 OpenOffice API。感谢SO,我弄清楚了如何打开行编号。现在我需要关闭页眉和页脚。 获取文档 XComponent 的 XPropertySet XPropertySet propSet = UnoRuntime.queryInterface(XPropertySet.class, 文档);
和设置
propSet.setPropertyValue("HeaderIsOn", Boolean.FALSE); propSet.setPropertyValue("FooterIsOn", Boolean.FALSE);
不工作。像许多其他人一样,我无法理解文档。
我看过一个 Perl 示例 ( Perl OpenOffice::OODoc - accessing header/footer elements ),但无法弄清楚如何在 Java 中获取“母版页”标题/样式。
救命啊!
最佳答案
获取页面样式并设置其属性。这是对我有用的代码:
XStyleFamiliesSupplier xSupplier = (XStyleFamiliesSupplier)
UnoRuntime.queryInterface(
XStyleFamiliesSupplier.class, xTextDocument);
XNameAccess xFamilies = (XNameAccess) UnoRuntime.queryInterface (
XNameAccess.class, xSupplier.getStyleFamilies());
XNameContainer xFamily = (XNameContainer) UnoRuntime.queryInterface(
XNameContainer.class, xFamilies.getByName("PageStyles"));
// The style name may be "Default Style" or just "Default" -- check your document.
XStyle xStyle = (XStyle) UnoRuntime.queryInterface(
XStyle.class, xFamily.getByName("Default Style"));
XPropertySet xStyleProps = (XPropertySet) UnoRuntime.queryInterface(
XPropertySet.class, xStyle);
xStyleProps.setPropertyValue ("HeaderIsOn", Boolean.FALSE);
xStyleProps.setPropertyValue ("FooterIsOn", Boolean.FALSE);
Perl UNO 示例可能很棘手,可能是因为它们使用自己特殊的 OpenOffice 库。相反,我发现这些很有帮助:
- Styles Example在 Java 中,位于页面底部。
- Changing the Text of Headers and Footers ,页面中间的基本示例。
关于java - OpenOffice API : How to turn off headers and footers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37492362/