导入到Excel中具有多个CSS类的HTML文件时出现问题 [英] Problems importing To Excel a HTML file With Multiple Css Classes On Elements
问题描述
如果HTML元素指向多个CSS类,则Excel似乎无法理解HTML属性类".
Excel looks that it does not understand the HTML attribute 'class' if several CSS classes are pointed for HTML element.
例如,如果"class ='A B'"指向标签"TD",则Excel将对标签使用空样式.
For example if "class='A B'" pointed to tag 'TD' Excel will use empty style for the tag.
我有以下html代码:
I have these 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>
如果我在IE中打开文件,则可以正确看到. 如果我在MS Excel中打开文件,那么我会看到错误.
If I open the file in IE, then I can see correctly. If I open the file in MS Excel, then I see wrong.
这是Office中的一个已知问题吗?
It this a a known problem in Office?
有人在这个问题上有经验吗?
Does anyone have any experience with this issue?
谢谢.
推荐答案
Excell不是Internet浏览器,并且不希望它解析CSS,它将仅使用包含类的元素,因此您需要使用以下代码:
Excell is not an internet browser and do not expect it to parse css, it will use only element containing classes, so you need to use this kind of 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>
这也很好,因为有时您需要定义Excell单元格类型,并且可以使用以下格式:
This is also good, because sometimes you need to define Excell cell-type and you can use following formats: http://cosicimiento.blogspot.co.at/2008/11/styling-excel-cells-with-mso-number.html
这篇关于导入到Excel中具有多个CSS类的HTML文件时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!