Wrox Programmer Forums
|
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 9th, 2008, 08:24 PM
Registered User
 
Join Date: Apr 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Export to Excel

I would like to export my dataview to excel. I have gotten something to work by using asp code but the problem is it send the html file to excel and if there are two pages of data, only the first page is captured. I have looked on the internet but the code is too cumbersome and since I will be using it on many pages I need something easier like a com.

Here is my code (copied from the net) but it works for one page at a time.


Response.ContentType = "Application/vnd.excel"
Response.AddHeader("Content-Disposition", "attachment; filename=MyIncidentReportFromQTS.xls")
Response.Write("<HTML xmlns:x=" & Chr(34) & "urn:schemas-microsoft-com:office:excel" & Chr(34) & ">")
Response.Write("<HEAD>")
Response.Write("<style>")
Response.Write(" <!--table")
Response.Write(" @page")
Response.Write(" {mso-data-placement:same-cell;}")


Anything in the new framework that has simplified this? Thanks.

-Ina Gaida Binta Single Baby
 
Old April 10th, 2008, 09:00 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I have had luck with just emitting a simple HTML table to the browser stream after specifying the content type.

What do you mean when you talk about "pages"? Do you mean different ASPX pages?

You could create a method in a utility class that does this if you want to share the functionality. The method could accept a data source or a control. You can render just the single control by creating your own instance of an HtmlTextWriter and calling the control's Render method, passing in the writer. Then emit the result to the Response stream and then end the response. That's how I have done it.

-Peter
peterlanoie.blog
 
Old April 10th, 2008, 09:25 AM
Registered User
 
Join Date: Apr 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What I meant by pages is this. My query might return hundreds of rows and I have my grid limit the table to 25 rows per page and therefore paging. My method specified does not take that into consideration as it only deals with whatever the browser is diaplaying.

Thanks for your response.
 
Old April 10th, 2008, 06:27 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Just turn off paging on the control when you emit it for the Excel download, and you'll get all the data.

-Peter
peterlanoie.blog
 
Old April 10th, 2008, 08:16 PM
Registered User
 
Join Date: Apr 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I already thought of that - what if there are 100's of records?

I am going to turn off paging for the time being till I figure out another way. Thanks for your reply.

-Ina Gaida Binta Single Baby
 
Old April 10th, 2008, 11:32 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You should be fine until you hit 65,535 rows (factoring in a header).

-Peter
peterlanoie.blog





Similar Threads
Thread Thread Starter Forum Replies Last Post
Export to excel moonbreeze Reporting Services 1 November 20th, 2006 08:42 PM
export to excel roy_mm Reporting Services 0 September 2nd, 2006 11:53 PM
Export to Excel using C# lily611 Crystal Reports 2 July 23rd, 2006 10:23 AM
excel export msrnivas Classic ASP Components 0 June 9th, 2004 10:15 PM
excel export msrnivas .NET Web Services 1 March 29th, 2004 03:21 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.