当我们将gridview导出到excel pllz时,如何在Excel中添加新行帮助我 [英] How Add new Row in Excel when we export gridview to excel pllz help me

查看:61
本文介绍了当我们将gridview导出到excel pllz时,如何在Excel中添加新行帮助我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们将gridview导出到excel pllz时如何在Excel中添加新行帮助我

How Add new Row in Excel when we export gridview to excel pllz help me

推荐答案

按照以下步骤

1.渲染GridView控件到HTMLTextWriter

2.将TextWriter内容复制到StringBuilder变量

3.准备一个html表行(< table>< tbody> ;< tr>< / tr>< / tbody>< / table> ),其中包含新行的值。每个列值应位于单独的< table>< tbody>< tr>< td>< / td>< / tr>< / tbody>< / table>

4.使用StringBuilder变量,将上面的行插入到结束表标记之前的html(

5.现在使用Response.Write编写内容()

6.这将使用您的新行下载excel



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.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();


这篇关于当我们将gridview导出到excel pllz时,如何在Excel中添加新行帮助我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆