473,732 Members | 2,205 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to transfer data from a GridView to an Excel worksheet.

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.InvokeMem ber(...) method:

Range range2 = worksheet.get_R ange("A1", "L1");
Object[] args2 = new Object[1];
args2[0] = header; // an array of 12 members
range2.GetType( ).InvokeMember( "Value", BindingFlags.Se tProperty,
null, range2, args2);

So I know how to do that. How do I extract the data from the
GridView???

Thanks in advance for your help.
Steve

Jul 13 '07 #1
2 2853
On Jul 13, 10:44 pm, Steve Kershaw <steve_kers...@ yahoo.comwrote:
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.InvokeMem ber(...) method:

Range range2 = worksheet.get_R ange("A1", "L1");
Object[] args2 = new Object[1];
args2[0] = header; // an array of 12 members
range2.GetType( ).InvokeMember( "Value", BindingFlags.Se tProperty,
null, range2, args2);

So I know how to do that. How do I extract the data from the
GridView???

Thanks in advance for your help.
Steve
hi,
try this modify a bit as your enviormrnt

//data view use for grid bing
protected DataView dvB = null;
protected void ExportToExcel()
{
Response.Clear( );
Response.AddHea der("content-disposition",
"attachment;fil ename=FileName. xls");
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);
DataGrid dg = new DataGrid();

//get table fron dataview....in your case some how try to
get the table
DataTable temp = dvB.Table.Clone ();
DataTable exportTable = dvB.Table;

for (int i = 0; i < temp.Columns.Co unt; i++)
{
if (temp.Columns[i].ColumnName.Con tains("Id") == true)
{

exportTable.Col umns.Remove(tem p.Columns[i].ColumnName);
}
}

dg.DataSource = exportTable;
dg.DataBind();
dg.RenderContro l(htmlWrite);
Response.Write( stringWrite.ToS tring());
Response.End();
}
hope help

nahid
http://nahidulkibria.blogspot.com/
http://www.kaz.com.bd

Jul 13 '07 #2
Hello,

Here you have to samples about how to export GridView to Excel (Quick way).

http://aspalliance.com/771
http://geekswithblogs.net/azamsharp/.../21/63843.aspx

If you want something more ellaborated you can use XMLSS.

HTH
Braulio

/// ------------------------------
/// Braulio DÃ*ez
///
/// http://www.tipsdotnet.com
/// ------------------------------


"Steve Kershaw" wrote:
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.InvokeMem ber(...) method:

Range range2 = worksheet.get_R ange("A1", "L1");
Object[] args2 = new Object[1];
args2[0] = header; // an array of 12 members
range2.GetType( ).InvokeMember( "Value", BindingFlags.Se tProperty,
null, range2, args2);

So I know how to do that. How do I extract the data from the
GridView???

Thanks in advance for your help.
Steve

Jul 14 '07 #3

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

Similar topics

3
9245
by: sridevi | last post by:
Hello How to export data from ms-access database to excel worksheet using ASP. mainly i need to export data to multiple worksheets. it is very urgent to us. i have a sample code which works only exporting to single worksheet. but i need to export data to multiple worksheets. it is very urgent to us. so please help me in code.
5
7587
by: hmiller | last post by:
Hey there folks: I have been trying to get this work for about a week now. I'm new to VBA... I am trying to transfer a populated table in Access to an existing, but blank, Excel worksheet. I have seen methods for transfering cell by cell, and understand how to get that to work. However, my recordset has 3600 cells of data. Cell by cell is just not an option. I am looking for a way to specify the starting cell (most upper left cell) in...
3
4117
by: JohnM | last post by:
I can transfer from a query with DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "Filenam", CPath, True I would like to use a form for the user to select and order data then export th result. How do I set about this?
0
3065
by: blainegray | last post by:
Greetings This is one of those Access is not closing Excel problems. The first time through the code works fine. The second time there is a problem. After lots of combinations, I finally determined that if I take out the line that copies the temp array to cells in a worksheet, Access will close the Excel file. If the line is there, Excel remains open and blocks more runs of the same procedure. If I close Access, Excel gets closed. Looks like...
0
12808
by: ntuyen01 | last post by:
Hi All, I try to read the data from the excel, but I ran into this problem I have two excel files. file one.xls data inside like this: 1234 1234 1234 1234 abc-123 abc-123
12
7136
by: cmghosh | last post by:
how to transfer excel worksheet data to mysql table?
1
2740
by: chuch0117291 | last post by:
Hi, i have a form with the main details of a vendor and and contract description and a budget reference(PK). Within this form, i have a sub form which includes cost details for that specific vendor but also has the same budget reference hence the link. I would like to create a command button to be able to export the data from the main form to an excel spreadsheet and the data from the sub form to excel spreadsheet tab2 from the click of a...
5
3217
by: billa856 | last post by:
Hi I am totaly new to MS Access. I have one worksheet in excel in which I have data of company's inventory. I want to know can I transfer data from a form made in MS Access to the Excel worksheet? Can I use access form to fetch or update data in excel worksheet? Can I use MS Access as frontend Or I have to use another frontend like VB?
2
1673
by: =?Utf-8?B?Y2xhcmE=?= | last post by:
Hi all, I have some data in a worksheet and need to be transfered to a table in SQL Server 2005 using VB 2005, the question is how can I manipulate the Excel object model and access to the data in the worksheet. Clara thank you so much for your help
0
8774
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9307
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
9235
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
9181
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6735
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
6031
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();...
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.