java - How can the Page Size, Page Orientation, and Page Margins of an ods Spreadsheet Be Set Using ODFDOM? -
the apache incubation project odfdom allows users programmatically read , create various open document format files, including spreadsheets.
i trying set various print options spreadsheet creating, using re-vamped "simple api", not appear have yet exposed easy way modify document properties such page margin, page size (height/width), , page orientation (landscape/portrait).
i need spreadsheetdocument allow me modify these values.
the necessary calls can made of underlying odf objects spreadsheetdocument provides access to. first, need proper document properties reference (for examples, "spreadsheet" reference created spreadsheetdocument):
stylemasterpageelement defaultpage = spreadsheet.getofficemasterstyles().getmasterpage("default"); string pagelayoutname = defaultpage.getstylepagelayoutnameattribute(); odfstylepagelayout pagelayoutstyle = defaultpage.getautomaticstyles().getpagelayout(pagelayoutname); pagelayoutproperties pagelayoutprops = pagelayoutproperties.getorcreatepagelayoutproperties(pagelayoutstyle);
then, can set various properties, such margins, orientation, , height/width. note height , width values seem required page orientation value work properly, , height ad width need height , width of orientation being used:
pagelayoutproperties.setpageheight(pageheightinmm); pagelayoutproperties.setpagewidth(pagewidthinmm); pagelayoutproperties.setprintorientation(printorientation.landscape); pagelayoutproperties.setmarginleft(leftmargininmm); pagelayoutproperties.setmarginright(rightmargininmm); pagelayoutproperties.setmargintop(topmargininmm); pagelayoutproperties.setmarginbottom(bottommargininmm);
i based off of another developer's notes on how original odfdom apis, , able change generated document's properties using code.
Comments
Post a Comment