I have upgraded aspose cells from 19.10 to 24.11 then I am facing issues if I save the file in xlsx format it is displaying file might be corrupted.
The code I am using to save the workbook :
workbook.save(
stream, createSaveOptions(getSaveFormat(reportFile.getMimetype()), reportFile.isPdfA()));
private Integer getSaveFormat(String mimeType) {
return mapExtensionToSaveFormat(MimeType.mapMimeTypeToExtension(mimeType));
}
private int mapExtensionToSaveFormat(String extension) {
return switch (extension.toLowerCase()) {
case “xlsx” → SaveFormat.XLSX;
case “pdf” → SaveFormat.PDF;
case “html” → SaveFormat.HTML;
default → SaveFormat.UNKNOWN;
};
}
private SaveOptions createSaveOptions(Integer saveFormat, boolean isPdfA) {
SaveOptions options;
// Handle save options, special case for PDF/A
if (SaveFormat.PDF == saveFormat && isPdfA) {
com.aspose.cells.PdfSaveOptions pdfAOptions = new com.aspose.cells.PdfSaveOptions();
pdfAOptions.setCompliance(com.aspose.words.PdfCompliance.PDF_A_1_A);
options = pdfAOptions;
} else if (SaveFormat.PDF == saveFormat) {
options = new PdfSaveOptions();
} else if (SaveFormat.HTML == saveFormat) {
options = new HtmlSaveOptions(saveFormat);
} else {
final int format = saveFormat;
options = new com.aspose.cells.XlsSaveOptions(format);
}
public class XlsSaveOptions extends SaveOptions {
boolean a;
public XlsSaveOptions() {
this.m_SaveFormat = 5;
}
public XlsSaveOptions(int saveFormat) {
if (saveFormat == 32) {
this.m_SaveFormat = 32;
} else {
this.m_SaveFormat = 5;
}
}
This code worked for xlsx in 19.10 version of aspose cells