导出时,inline css未在excel中显示 [英] inline css is not showing in excel when exporting

查看:83
本文介绍了导出时,inline css未在excel中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用内联css导出html表,但问题是css没有显示(div内联css我要显示)。

这里是我的html表的片段td

 <   td     class   =  progressColorGrade empPK_32   >  <   div     style   =  display:block; background-color:#00FF00 >   -  <   / div  >  <  < span class =code-leadattribute> / td  >  



我正在使用这个要在excel中导出



< pre lang =  < span class =code-string> xml>< script type =   text / javascript > 
var tableToExcel =( function (){
var uri = ' data:application / vnd.ms-excel; base64,'
,template = ' < html xmlns:o =urn:schemas-microsoft-com :office:officexmlns:x =urn:schemas-microsoft-com:office:excelxmlns =http://www.w3.org/TR/REC-html40>< head><! - [if gte mso 9]>< xml>< x:ExcelWorkbook>< x:ExcelWorksheets>< x:ExcelWorksheet>< x:Name> {worksheet}< / x:Name>< X:WorksheetOptions>< X:DisplayGridlines />< / X:WorksheetOptions>< / X:ExcelWorksheet>< / X:ExcelWorksheets>< / X:ExcelWorkbook>< / XML>< ENDIF! ] - >< / head>< body>< table> {table}< / table>< / body>< / html>'
,base64 = function (s){ return window .btoa( unescape (encodeURIComponent(s)))}
,format = function (s,c) { return s.replace(/ {(\w +)} / g, function (m,p ){ return c [p]; })
return function (table,name){
if (!table.nodeType)table = document .getElementById(table)
var ctx = {worksheet:name || ' 工作表',表:table.innerHTML}
window location .href = uri + base64(format(template,ctx))
}
})()
< / script>

解决方案

最后我想出了 [ ^ ]。使用嵌入式或外部CSS样式将无效。



观察



CSS必须是内联

CSS必须在表格的th或td元素上,因为它们代表excel中的CELLS (这是我的问题)

颜色应为十六进制




摘要从上面的代码中,我不需要外部CSS样式。我所有的css样式都需要在表中内联



可能还有更多需要观察的内容。请注意,请分享!!!!感谢。

I am trying to export html table with inline css but the problem is css is not showing (div inline css I want to show).
here is a snippet of my html table td

<td class="progressColorGrade empPK_32" ><div style="display : block; background-color:#00FF00">-</div></td>


while I am using this to export in excel

<pre lang="xml"><script type="text/javascript">
      var tableToExcel = (function () {
          var uri = 'data:application/vnd.ms-excel;base64,'
              , template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
              , base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))) }
              , format = function (s, c) { return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; }) }
          return function (table, name) {
              if (!table.nodeType) table = document.getElementById(table)
              var ctx = { worksheet: name || 'Worksheet', table: table.innerHTML }
              window.location.href = uri + base64(format(template, ctx))
          }
      })()
  </script>

解决方案

Finally i figured it out[^]. Using an embedded or external css style will not work.

Observations

CSS must be inline
CSS must be on th or td elements of the table because they represent CELLS in excel(This is what problem with me)
Colors should be HEX


SUMMARY From the above code, i dont need an external css style. All my css styles need to be inline in the table

There could be more to be observed. Please if you note any, please share!!!! Thanks.


这篇关于导出时,inline css未在excel中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆