Click here to Skip to main content
12,632,234 members (26,059 online)
Rate this:
Please Sign up or sign in to vote.
See more: ASP.NET
How Add new Row in Excel when we export gridview to excel pllz help me
Posted 17-Dec-12 0:07am
Lacy00 18-Dec-12 0:49am
I am afraid you have to add a new row in your gridview and then, export to Excel, or add a new row dircetly in yo9ur excel file after export
Mandy Nagra 18-Dec-12 3:11am
drictly in excl sheet
CandyT 18-Dec-12 22:33pm
You could add a new row after it is exported into excel

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Follow the below steps
1. Render GridView control to HTMLTextWriter
2. Copy TextWriter content to a StringBuilder variable
3. Prepare a html table row (<table><tbody><tr></tr></tbody></table>) with the values for the new row. Each column value should be within separate <table><tbody><tr><td></td></tr></tbody></table>
4. Using StringBuilder variable, insert the above row to the html just before end table tag ( )
5. Now write the content using Response.Write()
6. This will download an excel with your new row

            Response.AddHeader("content-disposition", "attachment;filename=Test.xls");
            Response.Charset = "";
            Response.ContentType = "application/vnd.xls";
            StringWriter stringWrite = new StringWriter();
            HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

            StringBuilder sb = new StringBuilder(stringWrite.ToString());
            sb = sb.Replace("</table>", "<tr><td>Column1</td><td>Column2</td></tr></table>");

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.161208.2 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100