Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forcing numeric values as text on HTML table exporting to excel

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

like image 278
RSolberg Avatar asked Apr 08 '11 17:04

RSolberg


People also ask

How do I export data from HTML table to Excel?

To convert HTML table data into excel, we need to use the SheetJS library. Using SheetJs we can easily convert our table data into an Xls file. We can download the js file from Github or directly use the CDN hosted file. We are done with HTML markup and import Sheetjs library.

How do I export a table to Excel?

Right-click on any cell in the table. Select Export Table. You can either Export to CSV or Export to Excel.


2 Answers

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

like image 146
Arun Singh Avatar answered Oct 13 '22 17:10

Arun Singh


Maybe try ="00212704"

Response.Write("<td class='tdsmall' align='left' NOWRAP>=""" & rsPODetail("ITM_ID") & """</td>")
like image 35
Jon Erickson Avatar answered Oct 13 '22 18:10

Jon Erickson