Hello,
When a worksheet contains a Chart which is not associated with any cell data, the Workbook becomes corrupt after it is saved by Aspose Cells.
This behavior can be seen under the latest Aspose Cells for Java version 21.6, the attached NoDataChart.xlsx
file and the following Java code:
String xlFile = [PATH] + "NoDataChart.xlsx";
Workbook wb = new Workbook(xlFile);
String newFile = xlFile.replace(".xlsx", "_aspose.xlsx");
Files.deleteIfExists(Paths.get(newFile));
wb.save(newFile);
System.out.println("Saved Workbook as: " + newFile);
Running the above code should produce a file similar to the attached NoDataChart_aspose_.xlsx
file. If you attempt to open the new file in Excel, a warning appears stating:
“We found a problem with some content in ‘NoDataChart_aspose.xlsx’. Do you want us to try to recover as much as we can? If you trust the source of this workbook, click Yes.”
Key Observations:
- The “no data chart” is a Clustered Column Chart type.
- If you click ‘Yes’ to the prompt from Excel, it removes the 2 embedded charts in the Workbook (one of which is valid and does have data).
- The culprit is the chart with no data. If you remove the chart with no data from the original Workbook, save it (in Excel) and rerun the above code - the newly generated workbook (saved by Aspose) is no longer corrupt.
Environment Details:
- Aspose Cells for Java 21.6
- Java version 1.8.0_211
- Windows 10 OS (but also reproducible under Linux).
File description in the NoDataChart.zip
(31.8 KB) attachment:
- NoDataChart.xlsx: Excel saved workbook to be used by the code above.
- NoDataChart_aspose.xlsx: Aspose saved workbook which cannot be opened by Excel.
- Excel_Error.png: Screenshot of error message when the corrupt workbook is opened by Excel.
Thank you!