Click here to Skip to main content
Rate this: bad
good
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
Comments
Member 9581488 at 17-Dec-12 9:24am
   
Please refer following link
http://www.e-iceblue.com/Knowledgebase/Spire.XLS/Demos/Pagesetup/Add-Row-in-Excel-Workbook-for-C-/VB.NET.html
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
good
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.Clear();
            Response.AddHeader("content-disposition", "attachment;filename=Test.xls");
            Response.Charset = "";
            Response.ContentType = "application/vnd.xls";
            StringWriter stringWrite = new StringWriter();
            HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
            
            GridView1.RenderControl(htmlWrite);
                      
 
            StringBuilder sb = new StringBuilder(stringWrite.ToString());
            sb = sb.Replace("</table>", "<tr><td>Column1</td><td>Column2</td></tr></table>");
           
            Response.Write(sb);
            Response.End();
  Permalink  

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

  Print Answers RSS
0 DamithSL 325
1 Maciej Los 217
2 OriginalGriff 213
3 BillWoodruff 79
4 Jose Garcia Sevilla 75
0 OriginalGriff 7,953
1 DamithSL 6,139
2 Sergey Alexandrovich Kryukov 5,454
3 Maciej Los 5,293
4 Kornfeld Eliyahu Peter 4,539


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