Apache孵化器项目ODFDOM允许用户以编程方式读取和创建各种打开的文档格式文件,包括电子表格。
我正在尝试为我正在创建的电子表格设置各种打印选项,使用它们重新包装的“简单API",但是它们似乎还没有公开一种修改文档属性的简单方法,如页边距、页面大小(高度/宽度)和页面方向(横向/纵向)。
我需要从一个SpreadsheetDocument到一些允许我修改这些值的东西。
发布于 2013-08-07 16:15:34
可以对SpreadsheetDocument提供访问权限的一些基础ODF对象进行必要的调用。首先,我们需要获得适当的文档属性引用(对于所有示例,“电子表格”是对创建的SpreadsheetDocument的引用):
StyleMasterPageElement defaultPage = spreadsheet.getOfficeMasterStyles().getMasterPage("Default");
String pageLayoutName = defaultPage.getStylePageLayoutNameAttribute();
OdfStylePageLayout pageLayoutStyle = defaultPage.getAutomaticStyles().getPageLayout(pageLayoutName);
PageLayoutProperties pageLayoutProps = PageLayoutProperties.getOrCreatePageLayoutProperties(pageLayoutStyle);然后,我们可以设置各种属性,如边距、方向和高度/宽度。请注意,页面定向值正常工作似乎需要高度和宽度值,而高度和宽度需要是所使用的方向的高度和宽度:
pageLayoutProperties.setPageHeight(pageHeightInMM);
pageLayoutProperties.setPageWidth(pageWidthInMM);
pageLayoutProperties.setPrintOrientation(PrintOrientation.LANDSCAPE);
pageLayoutProperties.setMarginLeft(leftMarginInMM);
pageLayoutProperties.setMarginRight(rightMarginInMM);
pageLayoutProperties.setMarginTop(topMarginInMM);
pageLayoutProperties.setMarginBottom(bottomMarginInMM);我基于如何使用原始ODFDOM完成此操作,并且能够使用此代码成功地更改生成的文档的属性。
https://stackoverflow.com/questions/18108452
复制相似问题