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

Free Support Forum - aspose.com

HTML to Excel - CSS Styling Ignored

We are currently working on implementing Aspose into our application for the purpose of converting data into various formats for reporting purposes. We are having an issue related to the conversion of HTML to Excel where the inline formatting in the table tags (TR, TH, etc) seem to be processed or partially processed but all other CSS related information is ignored completely. Our CSS File is fully qualified in the HTML so it can be found, as we discovered we’d have to do this when we implemented conversion of HTML to PDF.

I’ve also attempted to download our CSS Code into a CSS file and use the option to tell Aspose.Cells what directory has the CSS to no avail.

Attached is my XLSX file I got when converting and the HTML file I used as my source. We updated our Aspose.Cells from NuGet yesterday afternoon to 8.5.1 and it did not resolve the issue.

The code I am using to convert the HTML is as follows, please note that in this method I’m returning back the MemoryStream as it might be immediately saved to disk or shipped back if the request was done via one of our REST services. Either way the result is the same.

var htmlOptions = new HTMLLoadOptions();

Workbook workbook;

//If we are given raw HTML in a string, then we need to process it.
//Results have been identical when we use ASCII or UTF8, but we are using
//UTF8 as that is what is used in the Aspose.Cells Documentaiton examples.
if (isHtml)
workbook = new Workbook(new MemoryStream(Encoding.ASCII.GetBytes(source)), htmlOptions);
//We’ve got a file path, just pull the file up from Disk
workbook = new Workbook(source, htmlOptions);

var memoryStream = new MemoryStream();
workbook.Save(memoryStream, SaveFormat.Xlsx);

result.Value = memoryStream;

If any additional information is needed please let me know and I will do my best to provide what is required.


Thanks for the template files and details.

After an initial test, I observed the issue as you mentioned. I found CSS styling is ignored when converting your template HTML file to XLSX file format via Aspose.Cells APIs. The .css file is referenced/linked in the HTML as “https://mm.emsanyware.com/css/excel.css” and when I open the HTML file into MS Excel, it does display the HTML formatting with data fine and so does it convert to XLSX (in MS Excel manually) fine too.
Sample code:

var htmlOptions = new HTMLLoadOptions();

Workbook workbook;

workbook = new Workbook(“e:\test2\ExcelTable.html”, htmlOptions);

workbook.Save(“e:\test2\out1.xlsx”, SaveFormat.Xlsx);

I have logged a ticket with an id “CELLSNET-43831” for your issue. We will look into it soon.

Once we have any update on it, we will let you know here.

Thank you.


Thanks for using Aspose.Cells.

We have fixed
this issue now. We will provide you a fix in couple of days after
incorporating other enhancements and fixes and conducting some extensive
testing. Once, it is available for you, we will let you know asap by
posting in this thread.


Thanks for your using Aspose.Cells.

Please download and try the latest fix: Aspose.Cells for .NET v8.5.2.1 and let us know your feedback.

The issues you have found earlier (filed as CELLSNET-43831) have been fixed in this update.

This message was posted using Notification2Forum from Downloads module by Aspose Notifier.