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();
            }
        }

  • 相关阅读:
    【mpeg2】MPEG-2官方参考代码MPEG2_reference_software
    【base】Copyright 与 Copyleft
    【base】Copyright 与 Copyleft
    【complier】如何查看ARM交叉编译的可执行程序依赖的动态库?
    【shell系列】之查看shell脚本的执行过程和makefile中调试手段
    【tools】一款强大的局部搜索工具:xsearch
    【tools】一款强大的局部搜索工具:xsearch
    【mpeg2】mpeg2编码器的开源实现:x262
    【mpeg2】mpeg2解码器开源实现:libmpeg2
    【codecs】视频显示分辨率格式分析
  • 原文地址:https://www.cnblogs.com/sdya/p/4673579.html
Copyright © 2011-2022 走看看