Click here to Skip to main content
11,490,003 members (61,221 online)
Rate this: bad
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
Member 9581488 at 17-Dec-12 9:24am
Please refer following link
Lacy00 at 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 at 18-Dec-12 3:11am
drictly in excl sheet
CandyT at 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 (
) with the values for the new row. Each column value should be within separate

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
0 Sergey Alexandrovich Kryukov 600
1 Andy Lanng 233
2 OriginalGriff 208
3 Maciej Los 160
4 _duDE_ 141
0 Sergey Alexandrovich Kryukov 9,608
1 OriginalGriff 8,475
2 Sascha Lefèvre 3,419
3 Maciej Los 3,106
4 Richard Deeming 2,370

Advertise | Privacy | Mobile
Web02 | 2.8.150520.1 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2015
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