•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 427,014 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,512 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 6368 | Replies: 6
![]() |
•
•
Join Date: Jan 2007
Location: Japan
Posts: 70
Reputation:
Rep Power: 2
Solved Threads: 4
The simplest way is to export the file as a csv (comma seperated values) with a .xls extension which will open in excel although it's technically not an excel document, the alternative is to use the office interop for excel, only trouble with that is that office will need to be installed on the web server plus license. There are some components which do this kind of export e.g. aspose excel but obviously you would need to pay for it. Obviously in both cases the client would be prompted to save the file to their disk as the documents will be streamed from the webserver, having the application automatically save the document on the clients machine would be a lot more complex.
Heres a good article about the csv method:
http://www.dotnetspider.com/kb/Article963.aspx
Heres a good article about the csv method:
http://www.dotnetspider.com/kb/Article963.aspx
sedgey: so little daylight, too much caffeine
MCSD MCAD MCSE
http://www.thefriendlybuilder.co.uk,
http://www.sheetmusicdirect.com
MCSD MCAD MCSE
http://www.thefriendlybuilder.co.uk,
http://www.sheetmusicdirect.com
•
•
Join Date: Jan 2007
Location: Japan
Posts: 70
Reputation:
Rep Power: 2
Solved Threads: 4
This does code translation from C# to VB and vice versa:
http://www.carlosag.net/Tools/CodeTr...r/Default.aspx
http://www.carlosag.net/Tools/CodeTr...r/Default.aspx
sedgey: so little daylight, too much caffeine
MCSD MCAD MCSE
http://www.thefriendlybuilder.co.uk,
http://www.sheetmusicdirect.com
MCSD MCAD MCSE
http://www.thefriendlybuilder.co.uk,
http://www.sheetmusicdirect.com
•
•
Join Date: Jan 2007
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
I have found a really good example from microsoft at "http://support.microsoft.com/kb/317719". The author has added more than you need... I have used a datagrid not gridview on a new web form (copy their Bottom.aspx form only). I changed the code so you can send the page some SQL which will then be used to query the database and bind with the datagrid.
If you want to give the Excel form a name use this line: [Response.AddHeader("Content-Disposition", "attachment; filename=Exported.xls""")].
Then simply put a Response.Redirect at the end of the code to return you to the page you requested the function from. It appears instantaneously and you dont look like you navigate away from the page at all.
Hope this helps!
If you want to give the Excel form a name use this line: [Response.AddHeader("Content-Disposition", "attachment; filename=Exported.xls""")].
Then simply put a Response.Redirect at the end of the code to return you to the page you requested the function from. It appears instantaneously and you dont look like you navigate away from the page at all.
Hope this helps!
•
•
Join Date: Jan 2007
Location: Japan
Posts: 70
Reputation:
Rep Power: 2
Solved Threads: 4
http://support.microsoft.com/kb/317719: good article that
sedgey: so little daylight, too much caffeine
MCSD MCAD MCSE
http://www.thefriendlybuilder.co.uk,
http://www.sheetmusicdirect.com
MCSD MCAD MCSE
http://www.thefriendlybuilder.co.uk,
http://www.sheetmusicdirect.com
•
•
Join Date: Jan 2007
Posts: 47
Reputation:
Rep Power: 2
Solved Threads: 0
i m providing a code made necessary change at ur end.
Response.Clear()
Response.AddHeader("content-disposition", "attachment;filename=MyExcel.xls")
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = "application/vnd.xls"
Dim sw As StringWriter = New StringWriter
Dim htw As HtmlTextWriter = New HtmlTextWriter(sw)
dgdfiles.RenderControl(htw)
Response.Write(sw.ToString())
Response.End()
dgdfiles is the datagrid control id.
Response.Clear()
Response.AddHeader("content-disposition", "attachment;filename=MyExcel.xls")
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = "application/vnd.xls"
Dim sw As StringWriter = New StringWriter
Dim htw As HtmlTextWriter = New HtmlTextWriter(sw)
dgdfiles.RenderControl(htw)
Response.Write(sw.ToString())
Response.End()
dgdfiles is the datagrid control id.
![]() |
•
•
•
•
•
•
•
•
DaniWeb ASP.NET Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Updated : Simple ASP.Net Login Page (ASP.NET)
- Moving VB.NET Code to ASP.NET Code? (ASP.NET)
- Need Suggestion regarding sending sms through asp.net app (ASP.NET)
- Deploying ASP.NET application (ASP.NET)
- VS2005, SQLEXPRESS2005, ASP.NET config (ASP.NET)
- I Need Sample ASP.NET Code (ASP.NET)
- ASP in ASP.NET application (ASP.NET)
- ASP.NET <--> XML <--> VB6.0 (ASP.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: Download to Excel from Datagrid
- Next Thread: Create Table on SqlServer Through Asp.net coding


Linear Mode