Javascript 将html表格导出到Excel中

Javascript 将html表格导出到Excel中,javascript,html,excel,Javascript,Html,Excel,我想将html表格导出到Excel 表: <div id="table"> <table> <thead> <tr> <th>Column</th> <th>Column</th> </tr> </thead> <tbody id="tabbodyExp">

我想将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>

但excel正在将所有像“2.5”这样写的数字转换为日期。有没有办法阻止这种情况发生,或者我必须把所有的数字都写成“2,5”这样。

我在scunliffe的帖子中找到了答案:根据这篇帖子,你可以将这个特殊的CSS属性应用到表格单元格中,Excel将开始将值作为字符串来处理,而不是将其格式化为数字(希望这对你的日期同样有效):


我知道这是一个老问题,但我会添加我的答案,因为它可以帮助其他试图在excel中使用数字的用户

在我的例子中,
mso编号格式:“\@”不起作用,所以我使用
vnd.ms excel.numberformat:0.0

例如:

<th style="vnd.ms-excel.numberformat:0.0;">2.5</th>
2.5

2,5
mso-number-format:"\@"; /*force text*/
<th style="vnd.ms-excel.numberformat:0.0;">2.5</th>
<th style="vnd.ms-excel.numberformat:0.0;">2,5</th>