whilewk 2017-12-01 06:17 采纳率: 0%
浏览 1461

C#在谷歌浏览器中导出excel

具体代码如下

 System.Web.UI.WebControls.GridView DGOutPut = new System.Web.UI.WebControls.GridView();
                DGOutPut.Visible = true;
                DGOutPut.RowDataBound += new GridViewRowEventHandler(DGOutPut_RowDataBound);
                DGOutPut.DataSource = dt;
                DGOutPut.DataBind();
                System.Web.HttpContext.Current.Response.Clear();
                System.Web.HttpContext.Current.Response.Buffer = true;
                //System.Web.HttpContext.Current.Response.Charset = "GB2312";
                //System.Web.HttpContext.Current.Response.Charset = "UTF-8";

                System.Web.HttpContext.Current.Response.Charset = "GB2312";
                System.Web.HttpContext.Current.Response.ContentEncoding = Encoding.Default;
                System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName + ".xls", System.Text.Encoding.UTF8));
                //System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
                //System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
                System.Web.HttpContext.Current.Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。 
                DGOutPut.EnableViewState = false;
                System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
                System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
                System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
                DGOutPut.RenderControl(oHtmlTextWriter);
                System.Web.HttpContext.Current.Response.Write(@"<style> .text {mso-number-format:\@; } </style> ");
                System.Web.HttpContext.Current.Response.Write(oStringWriter.ToString());
                System.Web.HttpContext.Current.Response.Flush();
                System.Web.HttpContext.Current.Response.Close();
                //System.Web.HttpContext.Current.Response.End();
                //HttpContext.Current.ApplicationInstance.CompleteRequest();
                DGOutPut.DataSource = null;
                DGOutPut.Visible = false;

在谷歌中提示失败网络错误

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-12-01 06:18
    关注

    System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName + ".xls", System.Text.Encoding.UTF8));

    文件名里面有没有特殊符号

    评论

报告相同问题?

悬赏问题

  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题