"Cannot find central directory" error while opening Excel workbook

Hello, <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

am getting the following error while opening excel file.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: Aspose.Cells.OpenXML.฿: Cannot find central directory

Line 165: memoryStream.Seek(0, SeekOrigin.Begin);

Line 166: workbook.Open(memoryStream, Aspose.Cells.FileFormatType.Excel2007Xlsx, null);

Here is the code extract am using -

using (MemoryStream memoryStream = new MemoryStream(fileContents))

{

if (fileExt == ".xlsx")

{

Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook();

memoryStream.Seek(0, SeekOrigin.Begin);

workbook.Open(memoryStream, Aspose.Cells.FileFormatType.Excel2007Xlsx, null);

string previewHtml = GetHtmlFromDocument(workbook);

AddHtmlToControl(previewHtml);

}

}

private string GetHtmlFromDocument(Aspose.Cells.Workbook workbook)

{

using (MemoryStream documentStream = new MemoryStream())

{

workbook.Save(documentStream, Aspose.Cells.FileFormatType.Html);

using (StreamReader streamReader = new StreamReader(documentStream))

{

streamReader.BaseStream.Position = 0;

return streamReader.ReadToEnd();

}

}

}

What could be the problem? This is happening for any simple content as attached here.

Thanks and regards.

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for sharing the template file.

I have checked your scenario with the attached latest version of Aspose.Cells and it works fine. Please try the attached latest version of Aspose. If you still face any problem, please create a sample application to reproduce the issue and post it here. We will check it soon.

Thank You & Best Regards,