asp.net GridView导出到Excel代码
程序员文章站
2024-03-09 09:17:23
复制代码 代码如下:stringbuilder sb = new stringbuilder(); stringwriter sw = new stringwriter(s...
复制代码 代码如下:
stringbuilder sb = new stringbuilder();
stringwriter sw = new stringwriter(sb);
htmltextwriter htw = new htmltextwriter(sw);
page page = new page();
htmlform form = new htmlform();
gvlinkman.enableviewstate = false;
page.enableeventvalidation = false;
page.designerinitialize();
page.controls.add(form);
form.controls.add(gvlinkman);
page.rendercontrol(htw);
response.clear();
response.buffer = true;
response.contenttype = "application/vnd.ms-excel";
response.addheader("content-disposition", "attachment;filename=data.xls");
response.charset = "utf-8";
response.contentencoding = encoding.default;
response.write(sb.tostring());
response.end();
上一篇: asp.net(c#)ref,out ,params的区别
下一篇: Java中字符编码格式详解