Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format HTML table cell so that Excel formats as text?

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?

like image 340
dmr Avatar asked Jan 06 '11 21:01

dmr


People also ask

How do I change the text format in a cell?

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.


2 Answers

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> 
like image 91
scunliffe Avatar answered Sep 21 '22 15:09

scunliffe


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 (&#8203;) in the begining of the field.

like image 34
Raposo Avatar answered Sep 21 '22 15:09

Raposo