Problems importing into Excel an HTML file with multiple Css classes on elements

Excel looks like it does not understand the HTML attribute 'class' if multiple CSS classes are specified for an HTML element.

For example, if "class =" AB "points to the tag" TD ", Excel will use an empty style for the tag.

I have this HTML code:

<style type="text/css"> TABLE.t1_table{ background-color:#828a3c; border:solid 1px #3A6EA5; padding-left:2px; padding-top:2px; padding-right:2px; padding-bottom:2px; font-style:italic; font-variant:small-caps; font-size:20px; color:#6b3f07; border-collapse:collapse; 

}

 TR.t1_ph TD{ background-color:#B0C4DE; border:solid 1px #3A6EA5; padding-right:6px; font-weight:bold; color:#3A6EA5; 

}

 TR.t1_co TD{ background-color:#103a70; border:solid 1px #3A6EA5; padding-right:6px; 

}

 </style> <table class="t1_table" cellpadding="" cellspacing=""> <tr class="t1_ph"><td colspan="1">Age</td></tr> <tr class="t1_co"><td style="background-color:#cb7878">45</td></tr> <tr class="t1_co"><td>23</td></tr> </table> 

If I open the file in IE, then I can see it correctly. If I open the file in MS Excel, I see the wrong one.

Is this a known issue in Office?

Does anyone have any experience with this issue?

Thanks.

+4
source share
1 answer

Excell is not an Internet browser and does not expect it to analyze css, it will only use elements containing classes, so you need to use the following code:

 <style type="text/css"> .t1_table { background-color:#828a3c; border:solid 1px #3A6EA5; padding-left:2px; padding-top:2px; padding-right:2px; padding-bottom:2px; font-style:italic; font-variant:small-caps; font-size:20px; color:#6b3f07; border-collapse:collapse; } .t1_ph { background-color:green; border:solid 1px #3A6EA5; padding-right:6px; font-weight:bold; color:#3A6EA5; } .t1_co { background-color:red; border:solid 1px #3A6EA5; padding-right:6px; } </style> <table class="t1_table" cellpadding="" cellspacing=""> <tr><td class="t1_ph">Age</td></tr> <tr><td class="t1_co" style="background-color:#cb7878">45</td></tr> <tr><td class="t1_co">23</td></tr> </table> 

This is also good because sometimes you need to determine the type of Excell cell, and you can use the following formats: http://cosicimiento.blogspot.co.at/2008/11/styling-excel-cells-with-mso-number.html

0
source

Source: https://habr.com/ru/post/1338062/


All Articles