473,808 Members | 2,761 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3512
"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.AddHea der("content-disposition", "attachment;fil ename=FileName. xls");
Response.Charse t = "";
Response.Cache. SetCacheability (HttpCacheabili ty.NoCache);
Response.Conten tType = "applicatio n/vnd.xls";

System.IO.Strin gWriter stringWrite = new System.IO.Strin gWriter();
System.Web.UI.H tmlTextWriter htmlWrite = new HtmlTextWriter( stringWrite);

myDataGrid.Rend erControl(htmlW rite);
Response.Write( stringWrite.ToS tring());
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.AddHea der("content-disposition", "attachment;fil ename=FileName. xls");
Response.Charse t = "";
Response.Cache. SetCacheability (HttpCacheabili ty.NoCache);
Response.Conten tType = "applicatio n/vnd.xls";

System.IO.Strin gWriter stringWrite = new System.IO.Strin gWriter();
System.Web.UI.H tmlTextWriter htmlWrite = new HtmlTextWriter( stringWrite);

myDataGrid.Rend erControl(htmlW rite);
Response.Write( stringWrite.ToS tring());
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.AddHea der("content-disposition", "attachment;fil ename=FileName. xls");
Response.Charse t = "";
Response.Cache. SetCacheability (HttpCacheabili ty.NoCache);
Response.Conten tType = "applicatio n/vnd.xls";

System.IO.Strin gWriter stringWrite = new System.IO.Strin gWriter();
System.Web.UI.H tmlTextWriter htmlWrite = new HtmlTextWriter( stringWrite);

myDataGrid.Rend erControl(htmlW rite);
Response.Write( stringWrite.ToS tring());
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
2482
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 = Session("User") & "-Customer List-" & Today() sFile = sFile.Replace("/", "") RbtnExport.Visible = False Select Case RbtnExport.SelectedItem.Value Case "Excel" Response.ContentType = "application/x-msexcel"
8
2411
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 text boxes whichmakes the user to SCROLL a lot. I need only these 2 cloumns to be displayed in Edit mode. Is that possible & how? 2. Also, even when the data grid is not displayed in the edit mode, it
0
1742
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 data in a pivot table. Avoiding a 3rd party control is preferable. Thanks, Tim Response.ContentType = "application/vnd.ms-excel" Response.Charset = ""
4
2311
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 table is created then I need to fill the table with the data from that spreadsheet. I am using ASP.NET 2.0 and SQL 2000 for my database. What would be the best way to do this? Should I go Excel to XML or Excel to a Dataset?
9
2098
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", GetType(Double), "sum(Column_10_ld_act_125_gtr_fy_fy_hh_avg)")) where dt_stat_report_3b is my datatable, Sum is my column name and sum(Column_10_ld_act_125_gtr_fy_fy_hh_avg) is the sum of the column I needed. This Does return me the correct value in the...
1
6128
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 http://www.aspnetpro.com/NewsletterArticle/2003/09/asp200309so_l/asp200309so_l.asp
0
3447
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. When the user clicks on the Export to Excel button next to datagrid, it opens a popup with options Open, Save and Cancel. When I click open, it opens the excel sheet with the sheet name as .xls and the excel filename as temp.xls. As a result when...
2
2859
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 fill it with data using the Range.InvokeMember(...) method: Range range2 = worksheet.get_Range("A1", "L1"); Object args2 = new Object;
4
1926
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 create a new Excel spreadsheet and write data to it on the same computer, a computer that does not have Excel, or even Office installed. I have done some research on this and it appears it cannot be done. Can anyone verify that or better...
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10633
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10375
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9198
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7651
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6880
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3860
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.