HTML 到 Excel:如何告诉 Excel 将列视为数字? [英] HTML to Excel: How can tell Excel to treat columns as numbers?

查看:19
本文介绍了HTML 到 Excel:如何告诉 Excel 将列视为数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Excel 中打开 HTML 时需要实现以下目标 (Response.contentType="application/vnd.ms-excel") :

I need to achieve the following when opening an HTML in Excel (Response.contentType="application/vnd.ms-excel") :

  • 强制 Excel 将 td 单元格的内容视为数字
  • 进行上述操作,以便任何后续用户输入的公式都适用于这些单元格(打开电子表格时)

到目前为止,我成功地将 style="vnd.ms-excel.numberformat:0.00" 添加到有问题的 td 单元格中.当我在 Excel 中右键单击单元格时,单元格的内容正确显示为数字,但是公式不起作用.

So far I was successful with adding style="vnd.ms-excel.numberformat:0.00" to the td cells in question. The contents of the cells are correctly shown as numbers when I right click on them in the Excel, however the formulas don't work.

如果成功,该技术将非常有用,因为用户可以根据自定义要求使用适当的公式对任何 Web Excel 报表进行增强.提前致谢.

If successful, that technique would be quite useful because any web Excel report could be user enhanced with appropriate formulas according to custom requirements. Thanks in advance.

推荐答案

如果你给你的页面添加一个 CSS 类:

If you add a CSS Class to your page:

.num {
  mso-number-format:General;
}
.date {
  mso-number-format:"Short Date";
}

然后在你的 TD 上打这些课程,这行得通吗?

And slap those classes on your TD's, does it work?

<td class="num">34</td>
<td class="num">17.0</td>
<td class="date">12/17/2008</td> <!-- if you are playing with dates too -->

更新: 其他格式选项来自@Aaron.

这篇关于HTML 到 Excel:如何告诉 Excel 将列视为数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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