zoukankan      html  css  js  c++  java
  • 有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();
            }
        }

  • 相关阅读:
    vim 的列操作
    关于 matplotlib
    freemarker的常用内建函数
    三次握手与四次挥手
    layui动态表格生成
    layui 解决浏览器自动填充form表单账号和密码输入框的问题
    手机验证 和身份证验证
    把动态查询出来的集合数据,横向展示在页面
    eclipse安装freemarker插件
    目录文件树jQuery Ztree基本用法
  • 原文地址:https://www.cnblogs.com/sdya/p/4673579.html
Copyright © 2011-2022 走看看