导出HTML表格到Excel数字成为date

我想导出一个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”的数字转换为date。 有没有办法阻止,或者我必须写下所有的数字,如“2,5”。

我在这里find了scunliffe的post的答案: 格式化HTML表格单元格,使Excel格式为文本格式? 根据该post,您可以将这个特殊的CSS属性应用于表格单元格,Excel将开始将该值作为string处理,而不是将其格式化为数字(希望这对您的date来说是一样的):

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