HTML to Excel: How to tell Excel to treat columns as numbers


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

  • force Excel to consider content of td cells as numbers
  • make the above so that any subsequent user-entered formulas work on these cells (when the spreadsheet is opened)

So far I was successful with adding style="" 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.

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.

Best Answer

If you add a CSS Class to your page:

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

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 -->

Update: Additional formatting options from @Aaron.