private void Export(string FileType, string FileName)
{
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
GridView1.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
}
//如果没有下面方法会报错类型“GridView”的控件“GridView1”必须放在具有 runat=server 的窗体标记内
public override void VerifyRenderingInServerForm(Control control)
{
}
还有由于是文件操作所以要引入名称空间IO和Text
相关文章
- 08-20Excel小写金额转大写金额公式
- 08-20Open in Excel In Dynamics 365
- 08-20使用NPOI和线程池快速加载EXCEL数据
- 08-20与众不同 windows phone (52) - 8.1 新增控件: AutoSuggestBox, ListView, GridView, SemanticZoom
- 08-20使用SpringBoot+axios+hutool进行Excel的导出工作,并且在前端响应字符串的问题处理
- 08-20unity excel导出json 并解析 存在项目 dict内
- 08-20Apple导出p12证书 导出证书为p12 Apple开发
- 08-20.net 导出
- 08-20android – 无法在PopupWindow中为GridView执行OnItemClick
- 08-20导出数据子集:带where条件的exp导出