Hi,
Thanks for your patient waiting.
After further investigation, we found that the OutOfMemory error is related to JVM heap memory allocation, your input Excel has 50MB, it needs enough memory. Please change your code as below and increase the JVM to -Xms2048m -Xmx4096m. I have confirmed it can work well without OutOfMemory exception on my side. If you have any issue, just feel free to contact us.
- Code: Select all
Workbook workbook = new Workbook();
workbook.loadFromFile(path);
workbook.getConverterSetting().setSheetFitToWidth(true);
for (int i=0;i < workbook.getWorksheets().size();i++){
Worksheet worksheet = workbook.getWorksheets().get(i);
for (int col = worksheet.getFirstColumn();col<=worksheet.getLastColumn();col++){
CellStyle style = worksheet.getColumns()[col-1].getCellStyle();
style.setShrinkToFit(true);
style.setWrapText(false);
}
PageSetup pageSetup = worksheet.getPageSetup();
pageSetup.setPrintArea(null);
}
workbook.saveToFile(outputFileName, FileFormat.PDF);
workbook.dispose();
System.out.println("processed excel file - "+file.getName());
Sincerely,
Doris
E-iceblue support team