473,397 Members | 2,116 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

from datagrid to excel table

Syd
Hi all,
Is there a way to get data from a datagrid and send to an excel table?And if
it is possible how can arranged the excel table...
Thanks
Nov 17 '05 #1
3 3498
"Syd" wrote:
Hi all,
Is there a way to get data from a datagrid and send to an excel table?And if
it is possible how can arranged the excel table...
Thanks


Exporting data to Excel file is pretty simple. You just need to add few
headers. The DataGrid can be saved and opened with MS Excel or you can
directly open it in the browser as per your requirement.

<CODE>
Response.Clear();
// Content-disposition causes force download
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.No Cache);
Response.ContentType = "application/vnd.xls";

System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

myDataGrid.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
</CODE>

Find more information at:
http://www.codeproject.com/aspnet/DA...ortToExcel.asp

Hope it will help.

--
Cheers,
Rahul Anand

Nov 17 '05 #2
"Rahul Anand" wrote:
"Syd" wrote:
Hi all,
Is there a way to get data from a datagrid and send to an excel table?And if
it is possible how can arranged the excel table...
Thanks


Exporting data to Excel file is pretty simple. You just need to add few
headers. The DataGrid can be saved and opened with MS Excel or you can
directly open it in the browser as per your requirement.

<CODE>
Response.Clear();
// Content-disposition causes force download
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.No Cache);
Response.ContentType = "application/vnd.xls";

System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

myDataGrid.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
</CODE>

Find more information at:
http://www.codeproject.com/aspnet/DA...ortToExcel.asp

Hope it will help.

--
Cheers,
Rahul Anand


Just to add: the solution suggested above just saves the datagrid as HTML
Table and MS Excel application is intelligent enough to render the generated
HTML Table.

--
Cheers,
Rahul Anand
Nov 17 '05 #3
Syd
I think it works in ASP,Is there a other way??

"Rahul Anand" wrote:
"Rahul Anand" wrote:
"Syd" wrote:
Hi all,
Is there a way to get data from a datagrid and send to an excel table?And if
it is possible how can arranged the excel table...
Thanks


Exporting data to Excel file is pretty simple. You just need to add few
headers. The DataGrid can be saved and opened with MS Excel or you can
directly open it in the browser as per your requirement.

<CODE>
Response.Clear();
// Content-disposition causes force download
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.No Cache);
Response.ContentType = "application/vnd.xls";

System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

myDataGrid.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
</CODE>

Find more information at:
http://www.codeproject.com/aspnet/DA...ortToExcel.asp

Hope it will help.

--
Cheers,
Rahul Anand


Just to add: the solution suggested above just saves the datagrid as HTML
Table and MS Excel application is intelligent enough to render the generated
HTML Table.

--
Cheers,
Rahul Anand

Mar 3 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Steve Chatham | last post by:
I use the following code: Private Sub RbtnExport_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RbtnExport.SelectedIndexChanged Dim sFile As String =...
8
by: pmud | last post by:
Hi, I have 2 questions: 1. I have an editable data grid with 21 columns. I need to edit only 2 cloumns in this data grid. But when the grid is displayed in Edit mode, all the columns show long...
0
by: Tim_k | last post by:
Does anyone have an example of how to export a datagrid to an Excel pivot table? The code below exports the grid contents to Excel using the Response object. I'd like to expand it to show the...
4
by: washoetech | last post by:
Hello, I am working on a project where I need to be able to grab the data from an Excel spreadsheet and create a new table in my database based on the columns in the spreadsheet. After the...
9
by: Coleen | last post by:
Hi All :-) I found the way to get my column sum (Thanks Cor I did it a little different, but the result is what I wanted) I used: dt_stat_report_3b.Columns.Add(New DataColumn("Sum",...
1
by: Anonieko | last post by:
Here are some of the approaches. 1. Transform DataGrid http://www.dotnetjohn.com/articles.aspx?articleid=36 3. Use the Export approach ...
0
by: Sridhar | last post by:
Hi, I am having trouble renaming the excel sheet while exporting to excel. we have a datagrid that contains some analytical data. I have the name to the excel file as "temp.xls" inside the code....
2
by: Steve Kershaw | last post by:
Hi, I'm working on a project in which I have a Gridview that has data. That Gridview data must be then exported to an Excel spreadsheet. I have successfully displayed the Excel spreadsheet and...
4
by: zacks | last post by:
I have an application that can read an Excel spreadsheet on a computer that doesn't have Excel installed on using the Jet ODBC 4.0 driver. I know need to modify the application to also be able to...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.