Hello,
We are receiving a CellsException when we try to convert a workbook to a PDF file.
Although the CellsException doesn’t happen for all Workbooks, the exception is typically incurred when:
- There is an embedded chart within a worksheet.
- The Worsheet.removeUnusedStyles API is invoked.
The exception can be reproduced using the latest Aspose Cells version 17.10, the attached “WorkbookToPdf.xlsx” file and the following code:
try {
// provide full path to Workbook file
String fileName = "WorkbookToPdf.xlsx";
Workbook wb = new Workbook(fileName);
PdfSaveOptions saveOpts = new PdfSaveOptions(SaveFormat.PDF);
fileName = fileName.replace(".xlsx", "_aspose.pdf");
// NOTE: Commenting the following line circumvents the CellsException
wb.removeUnusedStyles();
wb.save(fileName, saveOpts);
} catch (Exception ex) {
System.out.println("Unexpected EXCEPTION: \n\t" + ex.getMessage());
ex.printStackTrace();
}
As noted in the code comment, we’ve observed that avoiding the invocation to the ‘removeUnusedStyles’ API, circumvents the issue. However, we require that this API be invoked.
Thanks.
WorkbookToPdf.zip (11.7 KB)
@oraspose
Thanks for your posting and using Aspose APIs.
We were able to observe this issue as per your description using the following code and found saving workbook as PDF after removeUnusedStyles API produces a CellsException.
We have logged this issue in our database for investigation. We will look into it and fix this issue. Once, the issue is resolved or we have some other news for you, we will let you know asap.
This issue has been logged as
-
CELLSJAVA-42452 - Saving a Workbook as PDF after RemoveUnusedStyles API produces a CellsException
Java
Workbook wb = new Workbook(dirPath + "WorkbookToPdf.xlsx");
//This line is important to produce exception
wb.removeUnusedStyles();
wb.save(dirPath + "out.pdf");
Exception
Exception in thread "main" com.aspose.cells.CellsException
at com.aspose.cells.zbyt.a(Unknown Source)
at com.aspose.cells.zbyt.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.save(Unknown Source)
at com.aspose.cells.Workbook.save(Unknown Source)
at ClsAsposeCells.f1(ClsAsposeCells.java:37)
at ClsAsposeCells.main(ClsAsposeCells.java:17)
@oraspose
Thanks for using Aspose APIs.
This is to inform you that we have fixed your issue CELLSJAVA-42452 now. We will soon provide the fix after performing QA and including other enhancements and fixes.
The issues you have found earlier (filed as CELLSJAVA-42452) have been fixed in this Aspose.Cells for Java 17.11 update.
Please also check the following document/blog for your reference: