Format HTML Table Cell So That Excel Formats as Text

Format HTML table cell so that Excel formats as text?

You can apply formatting to the cells for numbers, text, dates, etc.

See my previous answer on this: HTML to Excel: How can tell Excel to treat columns as numbers?

(adjusted snippet)

If you add a CSS Class to your page:

.num {
mso-number-format:General;
}
.text{
mso-number-format:"\@";/*force text*/
}

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

<td class="num">34</td>
<td class="num">17.0</td>
<td class="text">067</td>

Format html table cell numeric value as text for Excel

Answer Taken from:

https://stackoverflow.com/a/4620023/520848

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

Formatting can be applied to the cells for numbers, text, dates, etc.

by adding CSS class:

.num {
mso-number-format:General;
}
.text{
mso-number-format:"\@";/*force text*/
}

add the class to the cell

<td class="num">34</td>
<td class="num">17.0</td>
<td class="text">067</td>

Forcing numeric values as text on HTML table exporting to excel

Maybe try ="00212704"

Response.Write("<td class='tdsmall' align='left' NOWRAP>=""" & rsPODetail("ITM_ID") & """</td>")

How to format excel cell 'text' when opening an HTML content

I have found the answer for changing in html page. Please check the link.
Make <td> with CSS style mso-number-format:"\@";

How to keep format within HTML converted to Excel

you can achive that by using class. for example:

first add class

writer.WriteLine("<style> .number{mso-number-format:\"\\#\\#0\\.00\";} </style>");

and then, in your iteration :

writer.Write("<td class=\"number\" >");
writer.Write(data);
writer.WriteLine("</td>");

as shown in :
Export to Excel in ASP.NET, issue with decimal formatting for numbers greater than 1000



Related Topics



Leave a reply



Submit