export gridview to excel in asp.net
-
hi............. I have written following the code for export gridview to excel in asp.net protected void btnExcel_Click(object sender, EventArgs e) { string attachment = "attachment; filename=GridViewExport.xls"; Response.ClearContent(); Response.AddHeader("content-disposition", attachment); Response.ContentType = "application/ms-excel"; StringWriter sWriter = new StringWriter(); HtmlTextWriter htwWriter = new HtmlTextWriter(sWriter); gvCustomer.RenderControl(htwWriter); Response.Write(sWriter.ToString()); Response.End(); } It gives gridview in excel but not a normal excel file.......... how to do this.......... pls someone help me....... thnaks a lot
-
hi............. I have written following the code for export gridview to excel in asp.net protected void btnExcel_Click(object sender, EventArgs e) { string attachment = "attachment; filename=GridViewExport.xls"; Response.ClearContent(); Response.AddHeader("content-disposition", attachment); Response.ContentType = "application/ms-excel"; StringWriter sWriter = new StringWriter(); HtmlTextWriter htwWriter = new HtmlTextWriter(sWriter); gvCustomer.RenderControl(htwWriter); Response.Write(sWriter.ToString()); Response.End(); } It gives gridview in excel but not a normal excel file.......... how to do this.......... pls someone help me....... thnaks a lot
jadhavshubhangi wrote:
It gives gridview in excel but not a normal excel file..........
What do you mean by this? Not a normal excel file, what is the problem? there is a lot of code snippet available on google. Have a look
Cheers!! Brij Check my latest Article :URL Routing with ASP.NET 4.0
-
jadhavshubhangi wrote:
It gives gridview in excel but not a normal excel file..........
What do you mean by this? Not a normal excel file, what is the problem? there is a lot of code snippet available on google. Have a look
Cheers!! Brij Check my latest Article :URL Routing with ASP.NET 4.0
thanks for reply This excel sheet is not regular format like rows and columns only show gridview. Thanks
-
thanks for reply This excel sheet is not regular format like rows and columns only show gridview. Thanks
What is the extension of file you are getting? If its .xls then it is excel format. The gridlines might not be visible there, you have to add gridlines.
-
hi............. I have written following the code for export gridview to excel in asp.net protected void btnExcel_Click(object sender, EventArgs e) { string attachment = "attachment; filename=GridViewExport.xls"; Response.ClearContent(); Response.AddHeader("content-disposition", attachment); Response.ContentType = "application/ms-excel"; StringWriter sWriter = new StringWriter(); HtmlTextWriter htwWriter = new HtmlTextWriter(sWriter); gvCustomer.RenderControl(htwWriter); Response.Write(sWriter.ToString()); Response.End(); } It gives gridview in excel but not a normal excel file.......... how to do this.......... pls someone help me....... thnaks a lot
Actually you are saving HTML as Excel. That excel only shows the Grid's Gridlines. You can set gridlines manually by opening the excel. Or write a ActiveX to generate original excel using the Grid's data.
Castle Rider
What if I freeze??? Don't forget to breath...
My: Website | Yahoo Group | Blog Spot
/xml>
-
Actually you are saving HTML as Excel. That excel only shows the Grid's Gridlines. You can set gridlines manually by opening the excel. Or write a ActiveX to generate original excel using the Grid's data.
Castle Rider
What if I freeze??? Don't forget to breath...
My: Website | Yahoo Group | Blog Spot
/xml>
thanks for reply