Hi friend,
I have some sql data to display in grid view in button click.
|
S.No |
Enquiry_id |
Amount_paid |
Payment_mode |
sl_no |
|
1 |
1 |
1000.0000 |
Check |
1 |
|
2 |
2 |
500.0000 |
Check |
2 |
|
3 |
5 |
1500.0000 |
Check |
3 |
|
4 |
3 |
1500.0000 |
Check |
1 |
|
5 |
4 |
1000.0000 |
Cash |
2 |
I want to export grid view data to excel.
In that grid view remove few column in excel sheet. Using c# code to remove grid view column
Out put
|
S.No |
Amount_paid |
sl_no |
|
1 |
1000.0000 |
1 |
|
2 |
500.0000 |
2 |
|
3 |
1500.0000 |
3 |
|
4 |
1500.0000 |
1 |
|
5 |
1000.0000 |
2 |
foreach (GridViewRow drv in GridView1.Rows)
{
GridViewRow Temporaryheader = GridView1.HeaderRow;
GridViewRow Temporaryfooter = GridView1.FooterRow;
Temporaryheader.Cells[1].Visible = false;
Temporaryfooter.Cells[1].Visible = false;
drv.Cells[1].Visible = false;
Temporaryheader.Cells[3].Visible = false;
Temporaryfooter.Cells[3].Visible = false;
drv.Cells[3].Visible = false;
//---------
drv.Cells[1].Width = Unit.Pixel(1);
drv.Cells[3].Width = Unit.Pixel(5);
drv.Cells[3].Height = Unit.Pixel(10);
}
Export Excel:
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=Salary_Details.xls");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GridView1.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
If I export grid view data to excel, the excel sheet cell width not changed but changed in grid view not export to excel formatting width.
Please anyone help me immediately.
Thanks in Advance.
Upendra Pratap ShahiPosted Jun 30, 2015, 7:09 AM
RakeshPosted Jun 30, 2015, 5:54 AM
Jonathan SterlingPosted Jun 30, 2015, 5:35 AM
sharmila kPosted Nov 6, 2013, 1:47 AM
Thanks your reply.
I want export gridview data to excel work correctly but i want to change width and height in grdiview column to excel.
Please anyone help me immediatly.
Sanjay KumarPosted Nov 5, 2013, 10:47 AM
http://www.webcodeexpert.com/2013/06/how-to-bind-and-export-gridview-data-to_21.html
http://www.webcodeexpert.com/2013/06/bind-and-export-gridview-data-to-csv.html#.UnkR0VMw8eM
http://www.c-sharpcorner.com/uploadfile/hrojasara/export-gridview-data-in-csv-format/