Workbook workbook = new Workbook(excelPath);
Worksheet worksheet = workbook.getWorksheets().get(0);
PageSetup pageSetup = worksheet.getPageSetup();
pageSetup.setPaperSize(PaperSizeType.PAPER_A_4);
outputStream = new FileOutputStream(pdfPath);
PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.setOnePagePerSheet(true);
workbook.save(outputStream, saveOptions);
微信图片_20241206152627.png (196.7 KB)
@fan29
输出到PDF时设置一个工作表为一页时会忽略纸张的设置,如果你想显示空白部分,请使用PdfSaveOptions.setOnePagePerSheet(false)。
样例代码如下:
Workbook workbook = new Workbook(filePath + "20241020[null]测试机构开票信息-还款通知单.XLS");
Worksheet worksheet = workbook.getWorksheets().get(0);
PageSetup pageSetup = worksheet.getPageSetup();
pageSetup.setPaperSize(PaperSizeType.PAPER_A_4);
PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.setOnePagePerSheet(false);
workbook.save(filePath + "out_java.pdf", saveOptions);