By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,660 Members | 1,593 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,660 IT Pros & Developers. It's quick & easy.

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

P: 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
Share this Question
Share on Google+
5 Replies


Rabbit
Expert Mod 10K+
P: 12,370
That's because you haven't added any delimiters.
Jan 12 '12 #2

P: 28
how do i add those i am still new to vbscript
Jan 12 '12 #3

Rabbit
Expert Mod 10K+
P: 12,370
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

P: 28
I did just that and it worked Thanks a lot I reali appreciate it
Jan 13 '12 #5

Rabbit
Expert Mod 10K+
P: 12,370
No problem, good luck.
Jan 13 '12 #6

Post your reply

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