Response.ClearContent();
Response.AppendHeader("content.disposition", "attachment;filename=check.xls");
Response.ContentType = "application/ms-excel";
StringWriter strwriter = new StringWriter();
HtmlTextWriter htmlwriter = new HtmlTextWriter(strwriter);
GridView2.RenderControl(htmlwriter);
Response.Write(strwriter.ToString());
Response.End();
我正在尝试将数据导入excel所有代码执行得很好但是没有任何文件正在生成,请帮助我,我被卡住了。
答案 0 :(得分:0)
如果您更改content.disposition
的{{1}}:
content-disposition
还需要两个额外的设置:
1)必须在页面级别停用事件验证:
Response.AppendHeader("content-disposition", "attachment;filename=check.xls");
2)必须覆盖以下页面功能(它可以保持为空):
<%@ Page EnableEventValidation="false" ... %>