13

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).

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

Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet("new sheet");
Gagravarr
  • 47,320
  • 10
  • 111
  • 156
Georgy
  • 133
  • 1
  • 1
  • 4

1 Answers1

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

HSSFPrinterSetup Javadoc

Jacob
  • 41,721
  • 6
  • 79
  • 81
  • Thank you very much, this functions as expected. I missed this API. the only issue that there is no A6 available in the default formats, but I think I can try to find the closest one from the available. – Georgy Jul 19 '11 at 08:01
  • Thanks. The same applies to XSSF: e.g. `oSheet.getPrintSetup().setPaperSize(XSSFPrintSetup.A4_PAPERSIZE);` see: [poi.apache.org -> XSSFPrintSetup](https://poi.apache.org/apidocs/dev/org/apache/poi/xssf/usermodel/XSSFPrintSetup.html) – leole Oct 31 '19 at 09:25