468,512 Members | 1,469 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

How to insert text into an Excel file from a sql server database

28
I am working on a website and there is a need to export details that are stored on the database and put them in an excel file. I need to format the text such that each value appears in its own cell in that row. Right now they are all just appearing in one cell in that row.

The code I am using is shown below. The website is in classic ASP
Expand|Select|Wrap|Line Numbers
  1. ' Bulk Excel CSV export
  2.  
  3. If intShowPhoto = 5 then
  4.    Response.ContentType = "text/csv"
  5.     Response.Charset = "utf-8"
  6.     Response.AddHeader "Content-Disposition", "attachment; filename=Bulk_Exports.csv"
  7.     Do While Not objRecordset.EOF 
  8.     If objFirstName <> "" Then
  9.             Response.Write(objFirstName)
  10.             Response.Write("      ")
  11.             End If
  12.  
  13.             If objSurname <> "" Then
  14.             Response.Write(objSurname)
  15.             Response.Write("     ")
  16.             End If
  17.      If objTelMobile <> "" Then
  18.             Response.Write(objTelMobile)
  19.             Response.Write("     ")
  20.  
  21.         End If
  22.         If objEMail <> ""  Then
  23.            Response.Write(objEMail)
  24.            Response.Write(vbCRLF)
  25.  
  26.         End If
  27.  
  28.         objRecordset.MoveNext
  29.     Loop            
  30.     Response.End                
  31. End If
  32.  
Jan 12 '12 #1
5 2207
Rabbit
12,513 Expert Mod 8TB
That's because you haven't added any delimiters.
Jan 12 '12 #2
Rettla
28
how do i add those i am still new to vbscript
Jan 12 '12 #3
Rabbit
12,513 Expert Mod 8TB
You just need to write a comma after each field for a comma delimited file. Or a tab or a tab delimited file. Except at the end where you write a new line.

Also, it looks like you're not writing the new line if the email is a blank string. You have to write the new line no matter what.

And it looks like you're writing variables rather than the values in the recordset. That would be okay if you populated the variables with the values in the recordset but you don't do that.
Jan 12 '12 #4
Rettla
28
I did just that and it worked Thanks a lot I reali appreciate it
Jan 13 '12 #5
Rabbit
12,513 Expert Mod 8TB
No problem, good luck.
Jan 13 '12 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by ramnaresh_t yadav via .NET 247 | last post: by
2 posts views Thread by sympatico | last post: by
4 posts views Thread by sparty1022 | last post: by
6 posts views Thread by sejal17 | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.