zoukankan      html  css  js  c++  java
  • GridView 导出Excel或Word


        /// <summary>
        /// GridView 导出 Excel或Word
        /// </summary>
        /// <param name="gv"></param>
        /// <param name="fileType">文件类型</param>
        /// <param name="fileName">文件名</param>
        private void Exprot(GridView gv,String fileType, String fileName)
        {
            Response.Clear();
            Response.BufferOutput = true;
            //设定输出字符集  
            Response.Charset = "GB2312";
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.AppendHeader("Content-Disposition", "attachment;filename="
            + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
            //设置输出流HttpMiME类型(导出文件格式)  
            Response.ContentType = fileType;
            //关闭ViewState  
            Page.EnableViewState = false;
            System.IO.StringWriter sw = new System.IO.StringWriter();
            HtmlTextWriter textWriter = new HtmlTextWriter(sw);
            gv.RenderControl(textWriter);
            //把HTML写回游览器  
            Response.Write(stringWriter.ToString());
            Response.End();
            Response.Flush();
        }

       //重写此方法
        public override void VerifyRenderingInServerForm(Control control)
        {
            /*
            * asp.net2.0设置了内部变量控制RenderControl不允许在Render方法之外被轻易调用。 
            * 如果不override VerifyRenderingInServerForm就会报错。 
            * 我们override void VerifyRenderingInServerForm(Control control)这个方法, 
            * 里面不写任何代码即可*/
            //base.VerifyRenderingInServerForm(control);  
        } 

  • 相关阅读:
    StrBlobPtr类——weak_ptr访问vector元素
    StrBlob类——智能指针作为成员
    关于智能指针类型shared_ptr的计数问题
    桌面计算器——可调用对象练习
    union
    虚析构函数
    条款04 确定对象被使用前已先被初始化
    条款03 尽可能使用const
    Bugku-CTF之web8(txt????)
    Bugku-CTF之各种绕过
  • 原文地址:https://www.cnblogs.com/zhangqifeng/p/1524644.html
Copyright © 2011-2022 走看看