[ACCEPTED]-HTML to Excel: How can tell Excel to treat columns as numbers?-formulas

Accepted answer
Score: 29

If you add a CSS Class to your page:

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

And 2 slap those classes on your TD's, does it 1 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.

Score: 16

Here is a list of Excel formats: Styling Excel cells with mso-number-format


Score: 5

The best trick is to mock up an Excel spreadsheet 13 with all the colors/(conditional) formats/formulas 12 you require.

Keep it as simple as possible, just 11 the bare minimum rows etc.

Then save the 10 Excel spreadsheet "As Xml Spreadsheet"

Then 9 you have a template to build a spreadsheet 8 via Xml.

I generally clean up styles in the 7 original Xml saved from the Excel workbook. Removing 6 duplicates and renaming them.

Then it is 5 just a matter of populating with whatever 4 datasource you have.

I do not know what environment 3 you are coding to, but in VB.NET with LINQ 2 and Xml Literals, this is a very simple 1 task.

Score: 2

It doesn't works sometimes if you add it 4 using a css class in that case try it using in Style to 3 your TD. I did it for formatting a column 2 to a text. like this


For you it would be 1 as

Score: 1

I couldn't get any of the answers on this 2 page to work in Excel 2010. I ended up using 1 this.

<td x:num>123</td>
Score: 0

UPDATE: You also need to remove non-breaking 4 spaces (nbsp's) from td cells containing 3 numeric or money information to make formulas 2 work on these cells in Excel. So the problem 1 is solved.

More Related questions