p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   C# (http://p2p.wrox.com/forumdisplay.php?f=22)
-   -   Exporting data from datagrid to excel??? (http://p2p.wrox.com/showthread.php?t=70492)

twyce September 9th, 2008 03:12 PM

Exporting data from datagrid to excel???
 
I'm exporting data from a datagrid to an excel spreadsheet.I want the spreadsheet to open and display the data when the data is exported(when you click button export).How do i go about making that happen.Please help

Twyce!

robzyc September 9th, 2008 03:20 PM

Try looking up the Office PIA's they pretty much do everything you can do in Office to Office from .NET :D

Rob
http://cantgrokwontgrok.blogspot.com

samjudson September 9th, 2008 03:25 PM

This is by far and above THE most asked question on this forum, and shows a distinct lack of research on the part of anyone who asks it.

/- Sam Judson : Wrox Technical Editor -/

cikaPero March 4th, 2010 04:51 AM

Hi,

for exporting DataGrid to Excel in Excel ASP.NET application, I recommend you take a look at this Excel C# component.

It doesn't require Excel Automation and API is pretty simple and intuitive:

Code:

var people = (DataTable)dataGrid.DataSource;

// Create excel file.
var ef = new ExcelFile();
var ws = ef.Worksheets.Add("DataSheet");

ws.InsertDataTable(people, "A1", true);

Response.Clear();
Response.ContentType = "application/vnd.openxmlformats";
Response.AddHeader("Content-Disposition", "attachment; filename="
+ "Report.xlsx");

// With XLSX it is a bit more complicated as MS Packaging API
// can't write directly to Response.OutputStream.
// Therefore we use temporary MemoryStream.
var ms = new MemoryStream();
ef.SaveXlsx(ms);
ms.WriteTo(Response.OutputStream);

Response.End();



All times are GMT -4. The time now is 02:11 AM.

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