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.