页面设置 - 自适应页面设置

Aspose.Cells - 页面设置 - 自适应页面设置

要将工作表内容适配到特定页数,使用 PageSetup 类的 setFitToPagesTall 和 setFitToPagesWide 方法。这些方法也用于调整工作表。

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 - 页面设置 - 自适应页面设置

Apache POI SS 使用 setFitHeight 和 setFitWidth 方法进行自适应页面设置。

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

下载运行代码

下载示例代码