問題描述
在 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 將列視為數字?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!