Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
381 views
in Technique[技术] by (71.8m points)

c# - Exporting data from a gridview to different excel worksheets

I am binding data from a dataset to a grid and exporting data from the grid to 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??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...