zoukankan      html  css  js  c++  java
  • asp.net导出EXCEL的好方法!(好用,导出全部数据)

    1.调用方法:

    ExportExcel("application/ms-excel", "EXCEL名称.xls", GridView1, this.Page);


    2.定义方法:

     /// <summary>
            /// 另外一种存为EXCEL的方法
            /// </summary>
            /// <param name="FileType"></param>
            /// <param name="FileName"></param>
            /// <param name="gs"></param>
            /// <param name="page"></param>
            /// Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
            public static void ExportExcel(string FileType, string FileName, GridView gs, System.Web.UI.Page page)
            {
                if (gs.Rows.Count >= 65535)
                {
                    MessageShow("数据条数超过65535!无法导出请缩小查询范围!");
                    return;
                }
                Microsoft.Office.Interop.Excel.ApplicationClass eapp = new Microsoft.Office.Interop.Excel.ApplicationClass();
                eapp.Application.Workbooks.Close();
                eapp.Quit();
                page.Response.Charset = "GB2312";
                //  page.Response.ContentEncoding = System.Text.Encoding.UTF7;
                page.Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
                page.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
                page.Response.ContentType = FileType;
                page.EnableViewState = false;
                StringWriter tw = new StringWriter();
                HtmlTextWriter hw = new HtmlTextWriter(tw);
                gs.RenderControl(hw);
                page.Response.Write(tw.ToString());
                page.Response.End();
            }
  • 相关阅读:
    数字签名(代码签名)流程
    (转)__cdecl __fastcall与 __stdcall
    装修主材
    ATL 获取flash信息
    Windows结构化异常
    格式化HRESULT获取对应文本
    which type of VS files should be committed into a version control system
    读Windows核心编程-5-作业
    IE WebBrowser事件触发
    Windows 结构化异常
  • 原文地址:https://www.cnblogs.com/hfzsjz/p/3178402.html
Copyright © 2011-2022 走看看