zoukankan      html  css  js  c++  java
  • 导出Excel Gridview

    /// <summary>
        /// 定义导出Excel的函数
       
    /// </summary>
        /// <param name="FileType"></param>
        /// <param name="FileName"></param>
        private void Export(string FileType, string FileName)
        {


            GridView1.AllowPaging
    = false;    //导出分页的全部数据
            GridView1.AllowSorting
    = false;
            bind();
            Response.Charset
    = "GB2312";
            Response.ContentEncoding
    = System.Text.Encoding.UTF8;
            Response.AppendHeader(
    "Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
            Response.ContentType
    = FileType;
           
    this.EnableViewState = false;
            StringWriter tw
    = new StringWriter();
            HtmlTextWriter hw
    = new HtmlTextWriter(tw);
            GridView1.RenderControl(hw);
            Response.Write(tw.ToString());
            Response.End();
            GridView1.AllowPaging
    = true;    //导出分页的全部数据
            GridView1.AllowSorting
    = true;
            bind();
        }
       
    /// <summary>
        /// 此方法必重写,否则会出错
       
    /// </summary>
        /// <param name="control"></param>
        public override void VerifyRenderingInServerForm(Control control)
        {
        }
       
    protected void Button1_Click(object sender, EventArgs e)
        {

           
    Export("application/ms-excel", "123.xls");

        }


    还有由于是文件操作所以要引入名称空间IO和Text
    using System.Drawing;
    using System.IO;
    using System.Text

    轉:http://www.cnblogs.com/LifeKingcn/archive/2012/08/24/2654195.html

  • 相关阅读:
    Flash与JS之间相互调用以及参数传递
    在Javascript中监听flash事件(转)
    DataTables.js插入数据的两种方式
    DataTable在内存中的使用
    oracle分页存储过程
    清空highcharts数据
    JDBC源码分析(加载过程)
    MAVEN实现多环境搭建
    Maven基础
    Ajax如何提交数据到springMVC后台
  • 原文地址:https://www.cnblogs.com/axinno1/p/3474127.html
Copyright © 2011-2022 走看看