Page Setup - Fit to Page Setting
Contents
[
Hide
]
Aspose.Cells - Page Setup - Fit to Page Setting
To fit the contents of the worksheet to a specific number of pages, use the PageSetup class' setFitToPagesTall and setFitToPagesWide methods. These methods are also used to scale worksheets.
Java
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Accessing the first worksheet in the Excel file
WorksheetCollection worksheets = workbook.getWorksheets();
int sheetIndex = worksheets.add();
Worksheet sheet = worksheets.get(sheetIndex);
PageSetup pageSetup = sheet.getPageSetup();
// Setting the number of pages to which the length of the worksheet will
// be spanned
pageSetup.setFitToPagesTall(1);
// Setting the number of pages to which the width of the worksheet will be spanned
pageSetup.setFitToPagesWide(1);
Apache POI SS - HSSF & XSSF - Page Setup - Fit to Page Setting
Apache POI SS uses setFitHeight and setFitWidth methods for fit to page settings.
Java
Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
Sheet sheet = wb.createSheet("format sheet");
PrintSetup ps = sheet.getPrintSetup();
sheet.setAutobreaks(true);
ps.setFitHeight((short) 1);
ps.setFitWidth((short) 1);
Download Running Code
Download Sample Code
For more details, visit Setting Page Options.