Asp.net Gridview 导出到Excel[解决编码乱码问题]
程序员文章站
2022-07-01 18:27:57
[csharp]
public override void verifyrenderinginserverform(control control)
...
[csharp]
public override void verifyrenderinginserverform(control control)
{ }
protected void linkbutton2_click(object sender, eventargs e)
{
response.clear();
response.buffer = true;
response.charset = "gb2312";
response.contentencoding = system.text.encoding.getencoding("gb2312");
response.appendheader("content-disposition", "attachment;filename=\"" + system.web.httputility.urlencode("数据导出", system.text.encoding.utf8) + ".xls\"");
response.contenttype = "application/ms-excel";
system.io.stringwriter ostringwriter = new system.io.stringwriter();
system.web.ui.htmltextwriter ohtmltextwriter = new system.web.ui.htmltextwriter(ostringwriter);
this.label1.rendercontrol(ohtmltextwriter);
this.gridview1.rendercontrol(ohtmltextwriter);
response.output.write(ostringwriter.tostring());
response.flush();
response.end();
}
public override void verifyrenderinginserverform(control control)
{ }
protected void linkbutton2_click(object sender, eventargs e)
{
response.clear();
response.buffer = true;
response.charset = "gb2312";
response.contentencoding = system.text.encoding.getencoding("gb2312");
response.appendheader("content-disposition", "attachment;filename=\"" + system.web.httputility.urlencode("数据导出", system.text.encoding.utf8) + ".xls\"");
response.contenttype = "application/ms-excel";
system.io.stringwriter ostringwriter = new system.io.stringwriter();
system.web.ui.htmltextwriter ohtmltextwriter = new system.web.ui.htmltextwriter(ostringwriter);
this.label1.rendercontrol(ohtmltextwriter);
this.gridview1.rendercontrol(ohtmltextwriter);
response.output.write(ostringwriter.tostring());
response.flush();
response.end();
}
上一篇: 血糖高早餐食谱,让健康从简单的早餐开始
下一篇: 如何完全卸载Oracle