ASP export to excel problem - excel is changing characters
Posted on 2007-04-10
i'm using the following script to export an asp recordset as an excel file :
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment;filename=reg.xls"
<meta http-equiv="Content-Type" content="application/vnd.ms-excel charset=windows-1255">
<% set objconn=server.createobject("adodb.connection")
set objrs=objconn.execute("SELECT * FROM registration")
' Loop through each Field, printing out the Field Names
For i = 0 to objrs.fields.count - 1
varField = objrs(i).name
' varField = replace(varField,"reg_","")
'varField = replace(varField,"mailing_","")
<% next %>
' Loop through rows, displaying each field
while not objrs.eof
<% For i = 0 to objrs.fields.count - 1
<TD VALIGN=TOP><% = objrs(i) %></TD>
<% Next %>
in general this works quite well except i have now come across a problem.... one of the fields in the DB is "card number" which is a credit card number.... in the access db the data is taken from this field is defined as text and displays the info correctly (eg 4670210100354419)...
when this colum is exported to the excel file it is displayed something like this : 4.56345E+15 .... when iselect this number it displays the full number in the formula box at the top but this number is incorrect... in the example where the credit card number recorded in the access db is 4670210100354419 the number shown in the excel would be 4670210100354410 .... as you see the final number is changed to a zero...
does anyone have any suggestions as to how not to export to excel without these problems