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 API でこれを行う方法に関する別の開発者のメモに基づいており、このコードを使用して生成されたドキュメントのプロパティを正常に変更することができました。