• 有gridview汇出word和excel


        private void Export(GridView _gv, string filetype, string FileName)
        {
            if (filetype == "1")
            {
                string style = @"<style> .text { mso-number-format:@; } </script> ";
                Response.Clear();
                Response.Buffer = true;
                Response.Charset = "GB2312";
                Response.Write("<meta http-equiv=Content-Type content=text/html;charset=GB2312>");
                Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());//FileName.xls");
                Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
                Response.ContentType = "application/excel";//设置输出文件类型为excel文件。
                System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
                System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
                _gv.RenderControl(oHtmlTextWriter);
                Response.Output.Write(oStringWriter.ToString());
                Response.Flush();
                Response.End();
            }
            else
            {
                string style = @"<style> .text { mso-number-format:@; } </script> ";
                Response.Clear();
                Response.Buffer = true;
                Response.Charset = "GB2312";
                Response.Write("<meta http-equiv=Content-Type content=text/html;charset=GB2312>");
                Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
                Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
                Response.ContentType = "application/word";//设置输出文件类型为Word文件。
                System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
                System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
                _gv.RenderControl(oHtmlTextWriter);
                Response.Output.Write(oStringWriter.ToString());
                Response.Flush();
                Response.End();
            }
        }

  • 相关阅读:
    搭建woocomerce网站
    Cozmo 机器人编程环境搭建
    DevExpress Wizard的控件使用方法
    DevExpress 地图的控件使用方法
    DevExpress 摄像机的控件使用方法
    大疆第一人称视角眼镜goggle激活
    iis支持asp.net4.0的注册命令使用方法
    【转】PowerDesigner删除外键关系,而不删除外键列
    【转】ABP webapi三种方式
    【转】OAuth2.0的refresh token
  • 原文地址:https://www.cnblogs.com/sdya/p/4673579.html
Copyright © 2020-2023  润新知