2016-06-28 25 views
1

我想将一个html表格导出到Excel。将html表格导出为Excel数字变成日期

表:

<div id="table"> 
<table> 
    <thead> 
     <tr> 
      <th>Column</th> 
      <th>Column</th> 
     </tr> 
    </thead> 
     <tbody id="tabbodyExp"> 
     <tr> 
      <th>2.5</th> 
      <th>2.6</th> 
     </tr> 
    </tbody> 
</table> 
</div> 

脚本:

$("#btnExport").click(function (e) { 
    window.open('data:application/vnd.ms-excel,' + $('#table').html()); 
    e.preventDefault(); 
}); 

但Excel是打开要写入这样的 “2.5” 到日期所有数字。有没有办法阻止,或者我必须写下所有数字“2,5”。

回答

0

我在这里找到了关于scunliffe的帖子的答案:Format HTML table cell so that Excel formats as text?根据那篇文章,你可以将这个特殊的CSS属性应用于表格单元格,Excel将开始将该值作为字符串处理,而不是将其格式化为数字(希望这可以起作用同样适用于你的日期):

mso-number-format:"\@"; /*force text*/