I am creating an HTML table that will be opened as a spreadsheet in Excel. What HTML tag or CSS style can I use to "tell" Excel to display the cell's contents as text?
Format Part of a CellSelect the cell you want to format. In the formula bar, select the text you want to format. Select the text formatting you want to use. Press Enter.
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>
There is one problem using that solution (css style with number-format). The Excel gives the error "Number Stored as text" which can be inconvenient in some cases. To avoid this problem it's possible to use the ZERO WIDTH SPACE character (​) in the begining of the field.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With