We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose 8.5.1.3 - MS-Excel file with more than one sheet gives error when try to convert Excel to html

Hello,


Aspose 8.5.1.3 is not converting Excel to html properly when excel has more than one sheet.

Issue:

" fileContents is byte[] of TestAspose.xlsx files content "

using (MemoryStream memoryStream = new
MemoryStream(fileContents))<o:p></o:p>

{

Aspose.Cells.LoadOptions load = new Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.Xlsx);

Aspose.Cells.Workbook document = new Workbook(memoryStream, load);

using (MemoryStream documentStream = new MemoryStream())

{

document.Save(documentStream, Aspose.Cells.SaveFormat.Html);

documentStream.Position = 0;

System.IO.File.WriteAllBytes(@"C:\temp\Error.html", documentStream.ToArray());

}

}

Output Error.html is not proper.

Please find attached Excel file "TestAspose.xlsx" to reproduce this issue.





Hi Clariss,


Thank you for contacting Aspose support.

Please note, while converting the spreadsheet to HTML in memory, you have to explicitly specify the folder to store the child HTML files and other resources. Please check the following piece of code and give it a try on your side.

C#

using (MemoryStream memoryStream = new MemoryStream(File.ReadAllBytes(directory + “TestAspose.xlsx”)))
{
Aspose.Cells.LoadOptions load = new Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.Xlsx);
Aspose.Cells.Workbook document = new Aspose.Cells.Workbook(memoryStream, load);
using (MemoryStream documentStream = new MemoryStream())
{
document.Save(documentStream, new Aspose.Cells.HtmlSaveOptions() { AttachedFilesDirectory = directory + “error_files” });
documentStream.Position = 0;
System.IO.File.WriteAllBytes(directory + “Error.html”, documentStream.ToArray());
}
}

Thanks for the reply!


Did you run the code which i had given you and observed how the html output looks like (With Aspose.Cells 8.5.1.3)?

It is not proper HTML. I do not think this solution is going to change anything. Also in actual code we are not storing file to any location we are converting to stream and using that. Just to get output I have added the line “System.IO.File.WriteAllBytes(@“C:\temp\Error.html”, documentStream.ToArray());” so we can see the output (corrupted)

Because when we reverted to Aspose Cells 8.1.0.0 after that we are able to get good html file as a output.

Please try my code with Aspose.Cells 8.5.1.3 and let me know if you get good html.


Thank you!

Hi Clariss,


Thank you for writing back.

Previously, I tested the scenario against the latest version of Aspose.Cells for .NET 8.6.1 as I am supposed to recreate the problem while using the latest version of the API only. I ran your exact code where the resultant HTML could not be loaded with any of the browsers so I checked the HTML code that refers to child HTML pages (sheet00x.htm files) and other resources (.xml & .mso files) which are not supposed to be generated with your exact code snippet. You may open the Error.html in notepad and observe the lines 12~14 & 24~26 for the missing files. Please note, this behavior is similar in Aspose.Cells for .NET 8.5.1 as well. Now, I have tested the scenario against the Aspose.Cells for .NET 8.1.0 and have noticed that your code exports only the active worksheet (please check Error-8.1.0.html). This behavior to output only the active worksheet while exporting the spreadsheet to HTML in memory has been altered in the recent revisions of the API so if you wish to get the results same as of v8.1.0, you have to set the HtmlSaveOptions.ExportActiveWorksheetOnly property to true (please check Error-8.6.1.html).

Please feel free to write back in case you have further questions or concerns.