ASP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingASP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 27th, 2003, 12:29 PM
pauldoylecraig pauldoylecraig is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 5 pauldoylecraig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Export asp.net datagrid to excel

My code is in c# and is able to return the results to me on my local sever in a datagrid on the asp.net page.

I would like to add a button to the web form that once clicked would export the datagrid to EXCEL.

Any code or pointers on how to do this would be appreciated.

Paul

Reply With Quote
  #2  
Old March 28th, 2003, 11:28 AM
crazytrain81 crazytrain81 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 232 crazytrain81 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 17

Reply With Quote
  #3  
Old April 14th, 2010, 04:19 AM
CikaPero CikaPero is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2010
Posts: 1 CikaPero User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 45 sec
Reputation Power: 0
Hi, you can easily convert DataGrid to Excel with GemBox.Spreadsheet Excel C# library.

Here is a code snippet how to do it in your ASP.NET Excel app:
Code:
// Get DataTable that DataGrid is bound to.
var dataTable = (DataTable)dataGrid.DataSource;

// Create new ExcelFile.
var ef = new ExcelFile();
// Add new worksheet to the file.
var ws = ef.Worksheets.Add(dataTable.TableName);
// Insert the data from DataTable to the worksheet starting at cell "A1".
ws.InsertDataTable(dataTable, "A1", true);

// Stream file to browser.
Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment; filename=Employee.xls");
ef.SaveXls(Response.OutputStream);
Response.End();


For live web demo see:
http://www.gemboxsoftware.com/WebDemo/Index.aspx

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingASP Development > Export asp.net datagrid to excel


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap