Connecting Tech Pros Worldwide Forums | Help | Site Map

Export to excel from MS SQL using ASP

Newbie
 
Join Date: Aug 2009
Posts: 4
#1: Aug 3 '09
Hi Champs - I need little help from you all.

I am new to ASP and need to generate a code having functionality to export the query results to Excel.

Right now, the user is getting the report on the page itself and now i need to provide him fuctionality to export the same results in excel. I need to provide a button on the top and with the clik of it the user will able to export the whole data (query result data - already on the page) into excel sheet.

Please let me know how to do it. I have whole existing code for the page where query results are shown on webpage.

Thanks a lot.

Its really urgent.

Regards,
SP

GazMathias's Avatar
Expert
 
Join Date: Oct 2008
Location: Bristol, United Kingdom
Posts: 145
#2: Aug 3 '09

re: Export to excel from MS SQL using ASP


Hi,

Quote:
I am new to ASP and need to generate a code having functionality to export the query results to Excel.
ASP or ASP.NET?

If ASP:

I once wrote a library that would take the query results from a recordset and create a spreadsheet from it.

On the page you would just need to add this line where you would like a link to appear:

Expand|Select|Wrap|Line Numbers
  1. ExcelDownload xl, RS, "Speadsheets/KPIDeliveryStats Jun 09.xls"
  2.  
Where RS is a ByRef name of the Recordset.
Spreadsheets is a folder in your app's file system
xl is the name the library would give the Excel object instance it creates.

On page, you would see a "Create Spreadsheet" link that would change to "Excel File Generated - Click to download."

Obviously, this only creates spreadsheets from the recordset data, not what is displayed on screen.

Would that be of any use to you?

Gaz
Newbie
 
Join Date: Aug 2009
Posts: 4
#3: Aug 4 '09

re: Export to excel from MS SQL using ASP


Thanks Gaz,

I tried to put this string in my code. But not able to get it done.

Here is the code file. Can you please look into it and let me know where should i add this string

I have changed the file extension from asp to txt

Thanks for all your help.

Regards,
SP
Attached Files
File Type: txt SRQUERY.txt (24.8 KB, 84 views)
Newbie
 
Join Date: Aug 2009
Posts: 4
#4: Aug 4 '09

re: Export to excel from MS SQL using ASP


Th actual thing is:

I am creating a asp page that wiil fetch data from database and export that to excel.

Existing fuctionality is being acheived by creating an HTML table to display the data. Now that it displays the data correctly in IE, I want to it to be stored in excel file too by showing one extra button over there on the output screen for the query

Please help.

Thanks
GazMathias's Avatar
Expert
 
Join Date: Oct 2008
Location: Bristol, United Kingdom
Posts: 145
#5: Aug 4 '09

re: Export to excel from MS SQL using ASP


Hi,

The library of functions I mention in my previous post will export what comes out of the database to Excel in exactly the manner you describe.

How To Export Your Displayed Data To Excel

Please re-read my prior post and the above article and decide which method is right for you.

Gaz
Newbie
 
Join Date: Aug 2009
Posts: 4
#6: Aug 5 '09

re: Export to excel from MS SQL using ASP


Thanks a lot Gaz

It really worked for me. I was little confused, things are pretty clear now.
Actually, this is my first assignment in ASP and it was urgent too.


Thanks for all your help and support.

SP
Reply

Tags
asp, excel, export, ms sql


Similar ASP / Active Server Pages bytes