Question posted 2011 · +8 upvotes
I’m trying to fix a bug at work where in classic ASP a HTML table is being rendered and then sent to the client as an Excel file. I’ll spare the entire source code sample, but essentially we have one column that is alpha numeric, yet when the value starts with one or more zeros, the zeros disappear. I know this is standard Excel behavior for handling numbers, but I want it to treat the value as text. How can I do this?
The Cell In Question:
Response.Write("<td class='tdsmall' align='left' NOWRAP>" & rsPODetail("ITM_ID") & "</td>")
Examples
HTML | EXCEL
00212704 | 212704
00212336 | 212336
00212251 | 212251
Accepted answer +9 upvotes
Just add one line before your table
Response.Write("<style> TD { mso-number-format:@; } </style>");
Check this out: Export Gridview to Excel with rows formatted as text
Top excel Q&A (6)
- Shortcut to Apply a Formula to an Entire Column in Excel +335 (2011)
- How should I escape commas and speech marks in CSV files so they work in Excel? +136 (2012)
- Convert xlsx to csv in linux command line +96 (2012)
- How to create a link inside a cell using EPPlus +50 (2011)
- IF statement: how to leave cell blank if condition is false ("" does not work) +44 (2013)
- T-SQL: Export to new Excel file +44 (2012)
excel solutions on this site
.