显然可以为ods电子表格文档更改这些设置,但只有某些参数可以更改:
StyleMasterPageElement defaultPage = templateDocument.getOfficeMasterStyles().getMasterPage("Default");
String pageLayoutName = defaultPage.getStylePageLayoutNameAttribute();
OdfStylePageLayout pageLayoutStyle = defaultPage.getAutomaticStyles().getPageLayout(pageLayoutName);
TextProperties textProperties = TextProperties.getOrCreateTextProperties(pageLayoutStyle);
textProperties.setFontStyle(StyleTypeDefinitions.FontStyle.BOLD);
如何设置页面方向?我在API中找不到odt文档的任何参考。
答案 0 :(得分:0)
您可以使用PageLayoutProperties类更改页面大小和边距。
关于页面方向,您可以切换页面的宽度和高度以获得横向方向,但我不确定这是否是正确的方法。
public static void main(String[] args) throws Exception
{
TextDocument odt = TextDocument.newTextDocument(); // From the simple odftoolkit
odt.addParagraph("Test text...");
// Getting the page layout properties
StyleMasterPageElement defaultPage = odt.getOfficeMasterStyles().getMasterPage("Standard");
String pageLayoutName = defaultPage.getStylePageLayoutNameAttribute();
OdfStylePageLayout pageLayoutStyle = defaultPage.getAutomaticStyles().getPageLayout(pageLayoutName);
PageLayoutProperties pageLayoutProps = PageLayoutProperties.getOrCreatePageLayoutProperties(pageLayoutStyle);
// Setting paper size "letter", portrait orientation
pageLayoutProps.setPageWidth(215.9); // millimeter...
pageLayoutProps.setPageHeight(279.4);
odt.save(new File(System.getProperty("user.home"), "letter_portrait.odt"));
// Setting paper size "letter", landscape orientation : just switch width/height...
pageLayoutProps.setPageWidth(279.4);
pageLayoutProps.setPageHeight(215.9);
odt.save(new File(System.getProperty("user.home"), "letter_landscape.odt"));
// Setting paper size "legal", portrait orientation
pageLayoutProps.setPageWidth(216);
pageLayoutProps.setPageHeight(356);
odt.save(new File(System.getProperty("user.home"), "legal_portrait.odt"));
// And so on...
// And you can also set the page margins
pageLayoutProps.setMarginTop(10);
pageLayoutProps.setMarginBottom(10);
pageLayoutProps.setMarginRight(10);
pageLayoutProps.setMarginLeft(10);
}