FatCow Web Hosting
 
Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read Web Directory

Go Back   Webmaster Forum > Designing and Developing Websites > Programming > ASP / .NET

ASP / .NET Discussions and help on ASP and .NET programming.

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 03-20-2007, 10:31 AM
technoguy technoguy is offline
WMG Citizen
 
Join Date: Mar 2007
Posts: 436
iTrader: (0)
technoguy is on a distinguished road
Default Sending grid data to excel

I am binding data of table to grid. Now data is showing perfectly in the datagrid. I want to export this data in excel file. Is it possible to export grid data into excel file or word file?
Reply With Quote
Sponsored Links
Register and sign in to hide this ad block

  #2 (permalink)  
Old 03-21-2007, 06:36 AM
leodeveloper leodeveloper is offline
WMG Newcomer
 
Join Date: Mar 2007
Posts: 10
iTrader: (0)
leodeveloper is on a distinguished road
Default Export data from datagride to excel

yes the following code wil helps you

private void Page_Load(object sender, System.EventArgs e)

{

// Put user code to initialize the page here

//Bind the DataGrid to DataSet

DataGridToExcel (DataGrid1, Response);

}

protected void DataGridToExcel(DataGrid dGridExport , HttpResponse httpResp)

{

httpResp.Clear();

httpResp.Charset = "";

httpResp.ContentType = "application/vnd.ms-excel";

StringWriter stringWrite = new StringWriter();

HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

DataGrid dGrid = new DataGrid();

dGrid = dGridExport;

dGrid.HeaderStyle.Font.Bold = true;

dGrid.DataBind();

dGrid.RenderControl(htmlWrite);

httpResp.Write(stringWrite.ToString());

httpResp.End();

}


Allah Bless on you
Reply With Quote
  #3 (permalink)  
Old 03-21-2007, 09:28 AM
technoguy technoguy is offline
WMG Citizen
 
Join Date: Mar 2007
Posts: 436
iTrader: (0)
technoguy is on a distinguished road
Default

I have got the code but can you explain what for this is?

httpResp.ContentType = "application/vnd.ms-excel";

I am sorry to bother you but will it work on hosting server too?
Reply With Quote
  #4 (permalink)  
Old 03-22-2007, 06:15 AM
leodeveloper leodeveloper is offline
WMG Newcomer
 
Join Date: Mar 2007
Posts: 10
iTrader: (0)
leodeveloper is on a distinguished road
Default

http is protocole httpResp.ContentType define the page content type.

httpResp.ContentType

ok

ALLAH bless on you
Reply With Quote
  #5 (permalink)  
Old 06-06-2007, 01:26 PM
Honi Honi is offline
WMG Newcomer
 
Join Date: Jun 2007
Posts: 1
iTrader: (0)
Honi is on a distinguished road
Unhappy Export DataGrid data to excel

Hello
I used this procedure to generate an Excel file since three different functions. For two of these functions, the result is right. But for one of these functions each line of data is duplicated (two lines for each record).
Is there somebody who had this problem?
Do you have the idea of what could have involved this error?
How can I correct this?
Many thinks.



Quote:
Originally Posted by leodeveloper View Post
yes the following code wil helps you

private void Page_Load(object sender, System.EventArgs e)

{

// Put user code to initialize the page here

//Bind the DataGrid to DataSet

DataGridToExcel (DataGrid1, Response);

}

protected void DataGridToExcel(DataGrid dGridExport , HttpResponse httpResp)

{

httpResp.Clear();

httpResp.Charset = "";

httpResp.ContentType = "application/vnd.ms-excel";

StringWriter stringWrite = new StringWriter();

HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

DataGrid dGrid = new DataGrid();

dGrid = dGridExport;

dGrid.HeaderStyle.Font.Bold = true;

dGrid.DataBind();

dGrid.RenderControl(htmlWrite);

httpResp.Write(stringWrite.ToString());

httpResp.End();

}


Allah Bless on you
Reply With Quote
Reply


Thread Tools
Display Modes

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

All times are GMT. The time now is 04:43 PM.



Freelance Web Designers
Work At Home Forum
Ad Marketplace
Online Deals and Bargains
HostGator Reseller Hosting Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.0.0