| | |
Exporting ASP pages to Excel
Please support our ASP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2006
Posts: 20
Reputation:
Solved Threads: 0
Hi, I'm a web developer for a small company, I had programmed using ASP about six years ago, thus my skills are very rusty at the moment...recently, my boss had asked me to export the database information from the ASP pages to an Microsoft Excel file, allowing the users to save and type in the file name, if possible, can anyone offer any guidance, directions or tips in doing so...I will be greatly appreciated...thanks...
Hi,
There is a tricky way for solving your problem. If you create a HTML table which holds all the data you want to export as an excel file by writing an ASP page, and if you put the proper headers to your ASP page, your HTML table can be downloaded as an Excel file. And this excel file is nicely handled by MS Excel.
You can try the code below:
There is a tricky way for solving your problem. If you create a HTML table which holds all the data you want to export as an excel file by writing an ASP page, and if you put the proper headers to your ASP page, your HTML table can be downloaded as an Excel file. And this excel file is nicely handled by MS Excel.
You can try the code below:
ASP Syntax (Toggle Plain Text)
<% Response.ContentType = "application/vnd.ms-excel" Response.AddHeader "Content-Disposition", "filename=excelfile.xls" %> <table> <tr> <td>Category Name</td> <td>Category Description</td> </tr> <tr> <td>Software</td> <td>Holds data for software</td> </tr> <tr> <td>Hardware</td> <td>Hardware related data</td> </tr> </table>
•
•
Join Date: Mar 2006
Posts: 20
Reputation:
Solved Threads: 0
Thanks for your help, but I need to export the database data that is being displayed on an ASP page, to an Excel file, preferably if the filename can be entered by the user, any idea how I can do that?
Is there a predefined function or method in ASP that we can make use of?
Thanks for your time, and I will look forward to your reply...
Is there a predefined function or method in ASP that we can make use of?
Thanks for your time, and I will look forward to your reply...
•
•
•
•
Originally Posted by delizeka
Hi,
There is a tricky way for solving your problem. If you create a HTML table which holds all the data you want to export as an excel file by writing an ASP page, and if you put the proper headers to your ASP page, your HTML table can be downloaded as an Excel file. And this excel file is nicely handled by MS Excel.
You can try the code below:
ASP Syntax (Toggle Plain Text)
<% Response.ContentType = "application/vnd.ms-excel" Response.AddHeader "Content-Disposition", "filename=excelfile.xls" %> <table> <tr> <td>Category Name</td> <td>Category Description</td> </tr> <tr> <td>Software</td> <td>Holds data for software</td> </tr> <tr> <td>Hardware</td> <td>Hardware related data</td> </tr> </table>
If I don't understand wrong, you can do it as I explained. For example; Let me say I have a link says "Download all data as an Excel file" in my web site. It should go to an asp page when it is clicked, for example ; datatoexcel.asp.
You can create datatoexcel.asp such that at the top of the page "Response.ContentType = "application/vnd.ms-excel" is placed. Then you can dynamically get your data from your database as dynamically created tables into your asp file. So when "Download all data as an Excel file" link is clicked, your datatoexcel.asp file tell client's browser that an excel file is coming. So browser want to download file and let user to save file.
You can take look at this link : http://www.codetoad.com/asp_excel.asp
There is another way to create an excel file. In this method you create an office document object on the server side. But this requires that necessary component must be installed on the web server.
You can read this article about this method : http://www.4guysfromrolla.com/webtech/022801-1.shtml
You can create datatoexcel.asp such that at the top of the page "Response.ContentType = "application/vnd.ms-excel" is placed. Then you can dynamically get your data from your database as dynamically created tables into your asp file. So when "Download all data as an Excel file" link is clicked, your datatoexcel.asp file tell client's browser that an excel file is coming. So browser want to download file and let user to save file.
You can take look at this link : http://www.codetoad.com/asp_excel.asp
There is another way to create an excel file. In this method you create an office document object on the server side. But this requires that necessary component must be installed on the web server.
You can read this article about this method : http://www.4guysfromrolla.com/webtech/022801-1.shtml
•
•
Join Date: Mar 2006
Posts: 20
Reputation:
Solved Threads: 0
Thanks for your tip, I managed to get my ASP page working after spending some time on debugging it, I guess I'm really rusty afterall...
By the way, do you know how I can upload images to the web server, using ASP page, i.e. using some simple textboxes for the user to enter the path for the image etc?
Thanks for your aid in the previous problem, you are a life-saver....
By the way, do you know how I can upload images to the web server, using ASP page, i.e. using some simple textboxes for the user to enter the path for the image etc?
Thanks for your aid in the previous problem, you are a life-saver....
•
•
•
•
Originally Posted by delizeka
If I don't understand wrong, you can do it as I explained. For example; Let me say I have a link says "Download all data as an Excel file" in my web site. It should go to an asp page when it is clicked, for example ; datatoexcel.asp.
You can create datatoexcel.asp such that at the top of the page "Response.ContentType = "application/vnd.ms-excel" is placed. Then you can dynamically get your data from your database as dynamically created tables into your asp file. So when "Download all data as an Excel file" link is clicked, your datatoexcel.asp file tell client's browser that an excel file is coming. So browser want to download file and let user to save file.
You can take look at this link : http://www.codetoad.com/asp_excel.asp
There is another way to create an excel file. In this method you create an office document object on the server side. But this requires that necessary component must be installed on the web server.
You can read this article about this method : http://www.4guysfromrolla.com/webtech/022801-1.shtml
•
•
Join Date: Jan 2009
Posts: 1
Reputation:
Solved Threads: 0
Hi!
I followed the steps and I am getting page cannot be displayed message. Could you help me what's the problem with the following code:
Any suggestions? thank you
I followed the steps and I am getting page cannot be displayed message. Could you help me what's the problem with the following code:
asp Syntax (Toggle Plain Text)
<%@LANGUAGE="JAVASCRIPT"%> <!--#include file="Integra.asp" --> <% var Reviews_cmd = Server.CreateObject ("ADODB.Command"); Reviews_cmd.ActiveConnection = MM_Integra_STRING; Reviews_cmd.CommandText = "SELECT * FROM dbo.Test"; Reviews_cmd.Prepared = true; var Reviews = Reviews_cmd.Execute(); var Reviews_numRows = 0; %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style type="text/css"> <!-- .style1 {color: #000000} --> </style> <% Response.ContentType = "application/vnd.ms-excel" Response.AddHeader "Content-Disposition", "filename=Globe_CHE_DataCapture.xls" %> </head> <body> <table> <tr> <td><span class="style1">Category Name</span></td> <td><span class="style1">Category Description</span></td> </tr> <tr> <td><span class="style1">Software</span></td> <td><span class="style1">Holds <strong class="highlight">data</strong> for software</span></td> </tr> <tr> <td><span class="style1">Hardware</span></td> <td><span class="style1">Hardware related data</span></td> </tr> </table> <%=(Reviews.Fields.Item("EmpID").Value)%> </body> </html> <% Reviews.Close(); %>
Any suggestions? thank you
Last edited by peter_budo; Jan 14th, 2009 at 7:23 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
•
•
Join Date: Feb 2009
Posts: 3
Reputation:
Solved Threads: 0
I use VBscript:
which works, but I would like to do macro-like activities once Excel is opened which doesn't seem to work like selecting cells or ranges, etc. Not sure why this is so, because some people seem to think this works. For example, my table has hyperlinks which I'd like removed within Excel, but selecting the cells to delete the hyperlink doesn't work.
Best of luck,
Dean.
ASP Syntax (Toggle Plain Text)
<script language="VBScript" type="text/vbscript" > Sub ToExcel strCopy = MyTable.InnerHTML document.parentwindow.clipboardData.SetData "text", strCopy Set objExcel = CreateObject("Excel.Application") objExcel.Visible = True Set objWorkbook = objExcel.Workbooks.Add() Set objWorksheet = objWorkbook.Worksheets(1) objWorksheet.Paste objWorksheet.Rows(1).delete objWorksheet.Cells.ColumnWidth = 20 objWorksheet.Cells.EntireColumn.AutoFit objWorksheet.Cells.AutoFilter objWorksheet.Cells.EntireRow.AutoFit objWorksheet.Cells(1, 1).Select Hyperlinks.Delete For i=1 to 1000 objWorksheet.Cells(1, i).Select Selection.Hyperlinks.Delete objWorksheet.Range(4, i).Select Selection.Hyperlinks.Delete Next End Sub </script>
which works, but I would like to do macro-like activities once Excel is opened which doesn't seem to work like selecting cells or ranges, etc. Not sure why this is so, because some people seem to think this works. For example, my table has hyperlinks which I'd like removed within Excel, but selecting the cells to delete the hyperlink doesn't work.
Best of luck,
Dean.
Last edited by peter_budo; Feb 4th, 2009 at 2:20 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
•
•
Join Date: Feb 2009
Posts: 3
Reputation:
Solved Threads: 0
I use VBscript:
which works, but I would like to do macro-like activities once Excel is opened which doesn't seem to work like selecting cells or ranges, etc. Not sure why this is so, because some people seem to think this works. For example, my table has hyperlinks which I'd like removed within Excel, but selecting the cells to delete the hyperlink doesn't work.
Best of luck,
Dean.
ASP Syntax (Toggle Plain Text)
<script language="VBScript" type="text/vbscript" > Sub ToExcel strCopy = MyTable.InnerHTML document.parentwindow.clipboardData.SetData "text", strCopy Set objExcel = CreateObject("Excel.Application") objExcel.Visible = True Set objWorkbook = objExcel.Workbooks.Add() Set objWorksheet = objWorkbook.Worksheets(1) objWorksheet.Paste objWorksheet.Rows(1).delete objWorksheet.Cells.ColumnWidth = 20 objWorksheet.Cells.EntireColumn.AutoFit objWorksheet.Cells.AutoFilter objWorksheet.Cells.EntireRow.AutoFit objWorksheet.Cells(1, 1).Select Hyperlinks.Delete For i=1 to 1000 objWorksheet.Cells(1, i).Select Selection.Hyperlinks.Delete objWorksheet.Range(4, i).Select Selection.Hyperlinks.Delete Next End Sub </script>
which works, but I would like to do macro-like activities once Excel is opened which doesn't seem to work like selecting cells or ranges, etc. Not sure why this is so, because some people seem to think this works. For example, my table has hyperlinks which I'd like removed within Excel, but selecting the cells to delete the hyperlink doesn't work.
Best of luck,
Dean.
![]() |
Similar Threads
- read excel records in asp not refreshing (is the excel file cached) (ASP)
- Error publishing Asp pages on WinME, personal webserver (ASP)
- how to make changes in all the pages using asp (ASP)
Other Threads in the ASP Forum
- Previous Thread: Problem in MS Visual InterDev 6.0
- Next Thread: ASP SQL add, update and delete lines
| Thread Tools | Search this Thread |
archive asp asp.net aspandmssqlserver2005 aspandmssqlserver2005connection aspconnection connection database databaseconnection dreamweaver excel fso iis msmsql mssql2005 mssqlserver2005 mssqlserver2005andasp mssqlserverandasp opentextfile record searchbox selectoption single specfic sqlserver sqlserverconnection windows7





