开发者

Exporting data from a gridview to different excel worksheets

开发者 https://www.devze.com 2022-12-29 13:54 出处:网络
I am binding data from a dataset to a grid and exporting data from the grid to开发者_JAVA百科 an excel.if the the number of items in the grid is greater than 50000,an error message is displayed.

I am binding data from a dataset to a grid and exporting data from the grid to开发者_JAVA百科 an excel.if the the number of items in the grid is greater than 50000,an error message is displayed.

So i want to split the data and display it in different worksheets in excel.(Am working in a web application)

using this code for exporting to excel

gvExcel.DataSource = DTS;
gvExcel.DataBind();
Response.AddHeader("content-disposition", "attachment; filename= filename.xls");
         Response.ContentType = "application/excel";
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        gvExcel.RenderControl(htw);
        // Style is added dynamically
        Response.Write(style);
        Response.Write(sw.ToString());
        Response.End();

Can anyone help me on this??


Pretty sure you need to actually use the Excel API and create the document, not just an HTML version of it. Using the HtmlTextWriter is a bit disastrous and I hate downloading documents that use it because it's always a mess. I have to re-save it as an xls (because its really just HTML) and go through the process of fixing it.


Following links will be useful to do so..

http://www.codeproject.com/KB/office/ExportDataSetToExcel.aspx

http://www.c-sharpcorner.com/blogs/BlogDetail.aspx?BlogId=283

Hope this will help!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号