zoukankan      html  css  js  c++  java
  • asp.net的GridView导出到Excel

     protected void btnExcel_Click(object sender, EventArgs e)
            {
                string orderNumber = (Convert.ToInt64(DateTime.Now.ToString("yyyyMMddhhmmss"))).ToString();
                Response.Clear();
                Response.BufferOutput = true;
                //设定输出的字符集
                Response.Charset = "GBK";
                //假定导出的文件名为FileName.xls
                Response.AppendHeader("Content-Disposition", "attachment;filename=User_" + orderNumber + ".xls");
                Response.ContentEncoding = System.Text.Encoding.GetEncoding("GBK");
                //设置导出文件的格式
                Response.ContentType = "application/ms-excel";
                //关闭ViewState
                EnableViewState = false;
                System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo("ZH-CN", true);
                System.IO.StringWriter stringWriter = new System.IO.StringWriter(cultureInfo);
                System.Web.UI.HtmlTextWriter textWriter = new System.Web.UI.HtmlTextWriter(stringWriter);
                gridTrade.BackColor = Color.FromArgb(255, 255, 255);
                //gridTrade.Columns[9].Visible = false;
                gridTrade.RenderControl(textWriter);
                //把HTML写回浏览器
                Response.Write(stringWriter.ToString());
                Response.End();
            }
            public override void VerifyRenderingInServerForm(Control control)
            {

            }


    作者:追梦网络
    出处:http://www.cnblogs.com/dream844/
    本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

  • 相关阅读:
    ubuntu安装后要做什么
    JavaScript错误处理
    jQuery 事件
    display的用法
    百度排名的原理
    什么是ajax?
    CSS文档流
    引用CSS的方法
    jQuery的安装方式
    禁止WPS2019开机自启动
  • 原文地址:https://www.cnblogs.com/dream844/p/2465000.html
Copyright © 2011-2022 走看看