Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 9th, 2008, 09:24 PM
Registered User
 
Join Date: Apr 2008
Location: Kano, Kano, Nigeria.
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
  #2 (permalink)  
Old April 10th, 2008, 10:00 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
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
  #3 (permalink)  
Old April 10th, 2008, 10:25 AM
Registered User
 
Join Date: Apr 2008
Location: Kano, Kano, Nigeria.
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.
  #4 (permalink)  
Old April 10th, 2008, 07:27 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
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
  #5 (permalink)  
Old April 10th, 2008, 09:16 PM
Registered User
 
Join Date: Apr 2008
Location: Kano, Kano, Nigeria.
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
  #6 (permalink)  
Old April 11th, 2008, 12:32 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
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
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 3rd, 2006 12:53 AM
Export to Excel using C# lily611 Crystal Reports 2 July 23rd, 2006 11:23 AM
excel export msrnivas Classic ASP Components 0 June 9th, 2004 11:15 PM
excel export msrnivas .NET Web Services 1 March 29th, 2004 03:21 PM



All times are GMT -4. The time now is 03:41 AM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.