問(wèn)題描述
在 Excel 中打開(kāi) HTML 時(shí)需要實(shí)現(xiàn)以下目標(biāo) (Response.contentType="application/vnd.ms-excel")
:
I need to achieve the following when opening an HTML in Excel (Response.contentType="application/vnd.ms-excel")
:
- 強(qiáng)制 Excel 將 td 單元格的內(nèi)容視為數(shù)字
- 進(jìn)行上述操作,以便任何后續(xù)用戶輸入的公式都適用于這些單元格(打開(kāi)電子表格時(shí))
到目前為止,我成功地將 style="vnd.ms-excel.numberformat:0.00"
添加到有問(wèn)題的 td 單元格中.當(dāng)我在 Excel 中右鍵單擊單元格時(shí),單元格的內(nèi)容正確顯示為數(shù)字,但是公式不起作用.
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.
如果成功,該技術(shù)將非常有用,因?yàn)橛脩艨梢愿鶕?jù)自定義要求使用適當(dāng)?shù)墓綄?duì)任何 Web Excel 報(bào)表進(jìn)行增強(qiáng).提前致謝.
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.
推薦答案
如果你給你的頁(yè)面添加一個(gè) 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 -->
更新: 其他格式選項(xiàng)來(lái)自@Aaron.
這篇關(guān)于HTML 到 Excel:如何告訴 Excel 將列視為數(shù)字?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!