I have a crash when converting an Excel file to PDF with the following stacktrace:
com.aspose.cells.CellsException
at com.aspose.cells.zcau.a(Unknown Source)
at com.aspose.cells.zcau.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.save(Unknown Source)
The same code works fine with the 18.7 version.
The code is basically like that:
Workbook workbook = new Workbook(inputStream, LoadOptions(0));
int sheetCount = workbook.getWorksheets().getCount();
for (int s = 0; s < sheetCount; s++) {
Worksheet sheet = workbook.getWorksheets().get(s);
PageSetup pageSetup = sheet.getPageSetup();
pageSetup.setLeftMargin(MARGIN_CM);
pageSetup.setRightMargin(MARGIN_CM);
pageSetup.setTopMargin(MARGIN_CM);
pageSetup.setBottomMargin(MARGIN_CM);
pageSetup.clearHeaderFooter();
}
PdfSaveOptions options = new PdfSaveOptions();
options.setOnePagePerSheet(true);
workbook.save(outputStream, options); // <- here’s the crash
Thanks for the sample code segment and stack trace.
Please provide us your template Excel file (you may zip the file and attach it here). Also, provide the variable/object value to specify the margins. This will help us really to evaluate your issue precisely to consequently figure it out soon.
Thank you for providing the sample file. I have tried following code using Aspose.Cells for Java 18.9.x but could not observe any issue. You may please give it a try using latest version and share the feedback.
Workbook workbook = new Workbook(path + "Tests_Transfo_Tableurs.xlsx");
int sheetCount = workbook.getWorksheets().getCount();
for (int s = 0; s < sheetCount; s++) {
Worksheet sheet = workbook.getWorksheets().get(s);
PageSetup pageSetup = sheet.getPageSetup();
pageSetup.setLeftMargin(0.4);
pageSetup.setRightMargin(0.4);
pageSetup.setTopMargin(0.4);
pageSetup.setBottomMargin(0.4);
pageSetup.clearHeaderFooter();
}
PdfSaveOptions options = new PdfSaveOptions();
options.setOnePagePerSheet(true);
workbook.save(path + "output.pdf", options); // <- here’s the crash
Good to know that your issue is sorted out by the new version/fix. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.