ASP Classic export data to csv

Posted on 2011-10-26
Last Modified: 2012-05-12
In classic ASP below code exports the data to csv perfectly but on all  but on field1 it truncats the  leading zero from  "0023423" to 23423.  On export how can I keep value as   "0023423"

Response.ContentType = "application/"
Response.AddHeader "content-disposition","attachment; filename=filename.csv"

Response.Write( "ComumnName1,")
Response.Write( "ComumnName2")

Do Until RS.EOF
    Response.write """" & .Fields("Field1").value  & """" & ","
    Response.write """" & .Fields("Field2").value  & """" & ","
    Response.write "," & vbcrlf
Question by:Bharat Guru
    LVL 33

    Expert Comment

    Cast the value as a string instead of an integer.  Try...

    Response.write """" & CSTR(.Fields("Field1").value)  & """" & ","

    Accepted Solution

    It's a cell format issue. All "general format" cells in Excel get the leading zeros truncated off.

    You need to format the data in ASP like this: ="000092374234"

    This article explains it really well:


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
    This demonstration started out as a follow up to some recently posted questions on the subject of logging in: and…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now