java Apache POI:更改 Excel 工作表的页面格式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6743615/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 17:06:33  来源:igfitidea点击:

Apache POI: change page format for Excel worksheet

javaexcelapache-poi

提问by Georgy

Is there a way to change the page size and layout while creating the Excel document using Apache POI? The default one is A4-vertical, while I need A6-horizontal (landscape).

有没有办法在使用 Apache POI 创建 Excel 文档时更改页面大小和布局?默认是 A4 垂直,而我需要 A6 水平(横向)。

I don't think that this question requires code sample, the Excel document is created just as described in the manual:

我不认为这个问题需要代码示例,Excel文档是按照手册中的描述创建的:

Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet("new sheet");

回答by Jacob

sheet.getPrintSetup().setLandscape(true);
sheet.getPrintSetup().setPaperSize(HSSFPrintSetup.A5_PAPERSIZE); 

HSSFPrinterSetup Javadoc

HSSFPrinterSetup Javadoc