More CSS styling being ignored when converting HTML to XLSX

I tested CSS styling as part of HTML being converted to XLSX by Aspose 16.12.4.0. The following sample renders OK:

<html>
<head>
<title>Test</title>
<style type=“text/css”>
tr td {
text-align: center;
font-weight: bold;
color: red;
}
</style>
</head>
<body>
<table>
<tr><td>Should be red, centered, bold.</td></tr>
</table>
</body>
</html>
But if I change the CSS selector on line 5 (td th) by any of the following, styling is ignored. This is not in line with HTML import logic in Excel.
  • table td
  • table tr td
The same problem occurs when the cell has a CSS class, e.g. MyCell. Making this change to the HTML part:
<tr><td class=“MyCell”>Should be red, centered, bold.</td></tr>
The following CSS selector works OK:
  • .MyCell
But these selectors do not work:
  • td
  • td.MyCell
  • tr td
  • tr td.MyCell
  • tr .MyCell
  • table td
  • table td.MyCell
  • table .MyCell
  • table tr td
  • table tr td.MyCell
  • table tr .MyCell

There is similar behavior when both the row and the cell have a CSS class. Again, this selector works:

  • .MyCell
And these do not:
  • tr td
  • tr .MyCell
  • .MyRow td
  • .MyRow .MyCell
  • All variations that start with table.
For completeness, we could have a class on the row only:
<tr class=“MyRow”><td>Should be red, centered, bold.</td></tr>
These selectors work:
  • td
  • tr td

And these do not work:

  • .MyRow td
  • All variations that start with table.

Please let me know if you have any questions or need any help reproducing these issues.

Hi,


Thanks for providing us source HTML with details.

After an initial test, I observed the issue as you mentioned by using the following sample code. I found that some CSS styles regarding Table tags are ignored when converting HTML to XLSX file format. The same formatting issue occurs when the cell has a CSS class with different variations as I tested these variations as well.
e.g
Sample code:

string html = @"

Test
<style type="“text/css”">
table td {
text-align: center;
font-weight: bold;
color: red;
}





Should be red, centered, bold.


";

byte[] byteArray = Encoding.ASCII.GetBytes(html);
MemoryStream stream = new MemoryStream(byteArray);
Aspose.Cells.HTMLLoadOptions loadOptions = new Aspose.Cells.HTMLLoadOptions();
Workbook workbook = new Workbook(stream, loadOptions);

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

I confirmed when I change the CSS selector by the following, CSS styling is again ignored:
table tr td

I also confirmed that the same problem occurs when the cell has a CSS class, e.g. MyCell. Making this change to the HTML part:
Should be red, centered, bold.
These selectors do not work as I tested:
td
td.MyCell
tr td
tr td.MyCell
tr .MyCell
table td
table td.MyCell
table .MyCell
table tr td
table tr td.MyCell
table tr .MyCell

I have logged a ticket with an id “CELLSNET-45028” for the issue. We will check if we could enhance HTML import/rendering a bit. We will also check if we could evaluate/consider CSS styling class with all your other variations when parsing HTMLs as per your mentioned details.

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

Thank you.

Please specify which scenarios you meant when saying “I found that some CSS styles regarding Table tag(s) are ignored when converting HTML to XLSX file format. Moreover, MS Excel does ignore it when importing HTML to it, so it is not an issue with Aspose.Cells APIs by any means.” So that I can re-evaluate them.

PS please do not restrict any fix you make to TD alone; the same applies to TH tags. Please also take note of any possible cascading issues like the one reported by me earlier: <a href="

Hi,

held1353:
Please specify which scenarios you meant when saying "I found that some CSS styles regarding Table tag(s) are ignored when converting HTML to XLSX file format. Moreover, MS Excel does ignore it when importing HTML to it, so it is not an issue with Aspose.Cells APIs by any means." So that I can re-evaluate them.

I meant when I write the HTML in a file to save it (e.g to abc.html) manually and then open the file into MS Excel, the display is same as per the output file by Aspose.Cells:
e.g
abc.html

Test
tr > td {
text-align: center;
font-weight: bold;
color: red;
}
Should be red, centered, bold.

(Note: I tested almost all your variations by updated the bold chars)

For your information, as I said earlier, it is not an issue of Aspose.Cells APIs. Aspose.Cells does follow Ms Excel standards and specifications in parsing or rendering HTMLs. The HTML which Aspose.Cells supports is a kind of MS Excel oriented HTML and not a common HTML. Anyways, as we logged the ticket, so we will try to enhance the HTML parsing/rendering module in Aspose.Cells APIs. We will let you know once we have an update on it.

Thank you.
Hi,

held1353:
PS please do not restrict any fix you make to TD alone; the same applies to TH tags. Please also take note of any possible cascading issues like the one reported by me earlier:

In an attempt to be as complete as possible, I included a number of scenarios I did not test against all three renderers (being Aspose, Excel and any standards-compliant webbrowser); sorry about that.

Please ignore all the selectors that have the ‘child selector’ in them (’>’); Excel ignores rules with that selector. Looks very much like an Internet Explorer 6 legacy.

I have edited my question accordingly; removed all the selectors of the form ‘A > B’. Please let me know if you find any issues with the remaining scenarios.

I’m not sure what you are trying to say here. If I would not mention TH in my question, then you would only fix the issue for TD, and stick to the original behavior for TH? I would like a straight answer on that.

Hi,


Thanks for updating your original post.

We will surely ignore all the child selectors in them (’>’) as MS Excel ignores these rules. I have updated the logged ticket (“CELLSNET-45028”) to log complete details and also updated my reply here:
https://forum.aspose.com/t/21741

Please spare us some time to evaluate your issue in details.

Once we have an update on it, or we figure your issue out, we will let you know here.

Thank you.
Hi,

held1353:
I'm not sure what you are trying to say here. If I would not mention TH in my question, then you would only fix the issue for TD, and stick to the original behavior for TH? I would like a straight answer on that.

Please see my reply here and follow up your other thread:
https://forum.aspose.com/t/22318

Thank you.

Thanks for pointing this out; I wasn’t aware TH behavior was so flaky in Excel.

I hope you will consider both TD and TH cells when addressing the styling issue. I can imagine that making/keeping TH Excel-compliant can be an impossible task, so I will leave it up to your best judgment on how to implement that.

I think I’ve had enough of TH; Excel made a real mess there. I feel your pain… :wink:

Hi,


We have managed to reproduce the issue and logged it as “CELLSNET-45039” into our database for product team’s investigation. Please follow up your other thread for the issue:
<a rel=“nofollow” href="https://forum.aspose.com/t/22318

Thank you.

Hi,


Regarding the ticket “CELLSNET-45028”, I am afraid, we can’t support free CSS nicely for now or in short time. We are continuously working over the enhancements for importing HTML to MS-Excel format and will gradually incorporate CSS styles with their attributes one by one.

Thank you.