Xlsx file are displaying file might be corrupted with latest aspose cells version

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

@harsha23,

Thanks for the code snippet.

How do you create the file? Are you using XlsSaveOptions to save the file in XLSX format? If so, please use OoxmlSaveOptions instead, as XlsSaveOptions is intended solely for the XLS format. If this isn’t the issue and you’re still encountering a corrupted file, please provide a sample runnable Java program (complete source code without compilation errors) along with the template Excel or other files (any input and output files) so we can replicate the problem on our end. We will then investigate it promptly.

@amjad.sahi Thanks for the response this worked with OoxmlSaveOptions

@harsha23
I’m glad your problem has been resolved! If you have any other questions, please feel free to contact us。

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 if (SaveFormat.XLSX == saveFormat) {
// Use OoxmlSaveOptions for .xlsx files
options = new OoxmlSaveOptions(SaveFormat.XLSX);
} 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;
    }

}
After using OoxmlSaveOptions excels are being generated properly but I am facing issues to generate largeReportWithCoverPage where I am giving input in xslx format and trying to generate pdf as output 

The error is with email it is taking much time to send so facing timeout errors

@harsha23,

It seems like you’re encountering performance or timeout issues especially when sending the email with the generated PDF by Aspose.Cells. This could be due to the size or complexity of the report, or how the email is being processed on your end. You can save to PDF via Aspose.Cells and if the PDF is generated fine and instantly, then your issue might be nothing to do with Aspose.Cells. May be you could check your email service timeouts. Check the SMTP timeout settings for sending emails. Increase the timeout if possible to allow the email to be sent without being prematurely closed due to a long file transmission.

In case the issue with Aspose.Cells, kindly do share more details, sample project and sample files to reproduce the issue on our end, we will check it soon.

Before using OoXmlSaveOptions the document was sent in email within no time but now we are facing issues stating as timeout exceeded to send the email if increasing the SmtpClient timeout settings is the solution then why I didn’t faced timeout errors before using OoxmlSaveOptions?

@harsha23,

I am not sure about your scenario/case and why you send the document (even it is not saved/updated via OoxmlSaveOptions) in email. For your issue there may not be anything to do with Aspose.Cells APIs or your issue is not with Aspose.Cells. To confirm this, don’t involve sending email (module) and just save the Excel file to PDF via Aspose.Cells and check if it works instantly? If you still find the issue, kindly do share your sample project with resource files and we will look into it soon.

Few templates are failing to save in project and few of the templates are saving in our project but when we try to send email if it throwing timeout exception for the saved templates

Currently I am facing 2 issues :

  1. GenerateLargeReportWithCoverPageMaxNoOfRowsPerPdf it is not even saving in our client page so I am not sending email for this scenario
    2.With GenerateLargeReportWithCoverPage it is saving in our client page but when we try to send the email of the saved file it is throwing timeout exception as mentioned earlier

@harsha23,

In order to accurately assess your issue on our side, we require sample projects and resource files. Kindly do provide the following artifacts (please compress them into zip file(s) before attaching):

  1. Two standalone (executable) sample projects (complete source code without any compilation errors) to replicate the issues you mentioned. You may exclude Aspose.Cells.Dll to minimize the size of the archive.
  2. Sample Excel files (any input Excel files and output files), PDF files (if applicable) or other files related to the two issues you pointed out.

Once we receive the sample apps along with the resource sample files or other files, we will begin our investigation and address your issue.