Excel导出为html无法在Excel 2016中显示边框

Sun*_*nil 5 javascript css export-to-excel

我正在xls使用JavaScript 将html导出到Excel 文件,如下面的演示:http://js.do/sun21170/84913.我使用谷歌浏览器来运行此演示,但它也应该在Edge或IE或FireFox中运行.

问题是当我打开导出的文件时Excel 2016,它显示没有任何边框,即使导出的html中有CSS显示边框.

问题:在Excel中打开html文件时,有没有办法显示边框?在Excel中打开的相同html,在浏览器中使用边框呈现,因此边框的CSS是正确的.http://js.do/sun21170/84913上的演示也显示了保存在Excel文件中的html.

缺少边框的Html表

HTML保存为xls文件

<html>
   <head>
      <style> table, td {border:1px solid black} table {border-collapse:collapse}</style>
   </head>
   <body>
      <table>
         <tr>
            <td>Product</td>
            <td>Customer</td>
         </tr>
         <tr>
            <td>Product1</td>
            <td>Customer1</td>
         </tr>
         <tr>
            <td>Product2</td>
            <td>Customer2</td>
         </tr>
         <tr>
            <td>Product3</td>
            <td>Customer3</td>
         </tr>
         <tr>
            <td>Product4</td>
            <td>Customer4</td>
         </tr>
      </table>
   </body>
</html>
Run Code Online (Sandbox Code Playgroud)

Sun*_*nil 6

经过大量研究后我终于找到了答案.看来Excel 2016不喜欢边框厚度1px; 大于1px的任何东西,如2px或3px或4px都有效.为什么Excel 2016的表现如此,我不清楚.

显示此信息的演示位于以下URL:http://js.do/sun21170/84961

此外,如果在任何其它单元如电磁或Pt或毫米,然后厚度为指定了边界厚度1em1mm1pt1mm.5mm将工作.

即使边框粗细像使用预先定义的值thinmediumthick在Excel 2016工作.

So, the lesson I have learnt is to never specify border thickness of 1 px when using Excel.

以下CSS是在Excel 2016中用于创建边框的不同样式.

边框厚度大于1px WORKS

var table = "<html><head><style> table, td {border:2px solid black}
            table {border-collapse:collapse}</style></head><body><table><tr>";
Run Code Online (Sandbox Code Playgroud)

边框厚度为1pt WORKS

var table = "<html><head><style> table, td {border:1pt solid black}
            table {border-collapse:collapse}</style></head><body><table><tr>";
Run Code Online (Sandbox Code Playgroud)

边框厚度1mm WORKS

var table = "<html><head><style> table, td {border:1mm solid black}
            table {border-collapse:collapse}</style></head><body><table><tr>";
Run Code Online (Sandbox Code Playgroud)

边框厚度为1em WORKS

var table = "<html><head><style> table, td {border:1em solid black}
            table {border-collapse:collapse}</style></head><body><table><tr>";
Run Code Online (Sandbox Code Playgroud)

薄薄的边框厚度

var table = "<html><head><style> table, td {border:thin solid black}
            table {border-collapse:collapse}</style></head><body><table><tr>";
Run Code Online (Sandbox Code Playgroud)