zoukankan      html  css  js  c++  java
  • DataGrid 导出 EXCEL(简单,实用)

    Response.ContentEncoding = 
    // 有时用 gb2312 不能正常显示中文,要用 utf-8
    System.Text.Encoding.GetEncoding("GB2312"); 
    Response.AppendHeader(
    "Content-Disposition""attachment;filename=" + "result.xls"); //必要,做成下载文件

    //如果要直接在浏览器中打开,把上行注释掉,换成下面这行
    //Response.ContentType = "application/vnd.ms-excel";    
       Response.Charset = ""// 从Content-Type header中去除charset设置

       
    //关闭 ViewState
       this.EnableViewState = false ;
          System.IO.StringWriter tw 
    = new System.IO.StringWriter();

       System.Web.UI.HtmlTextWriter hw 
    = new HtmlTextWriter(tw);
       
    //获取control的HTML
       DataGrid1.RenderControl(hw);
       
    //把HTML写回浏览器
       Response.Write(tw.ToString());
       Response.End();

    超精简,实用.


    如果DataGrid用了自动分页,那要在上面的程序之前加上:
    DataGrid1.AllowPaging 
    = false;
    BindDataGrid(); 
    // 重新绑定.
    ..
    // 上面的输出代码
    ..
    DataGrid1.AllowPaging 
    = true;

  • 相关阅读:
    系统信息查看命令
    item pipeline 实例:爬取360摄像图片
    scrapy之 downloader middleware
    scrapy 中用selector来提取数据的用法
    Live2D 看板娘
    Live2D 看板娘
    Live2D 看板娘
    Live2D 看板娘
    Live2D 看板娘
    Live2D 看板娘
  • 原文地址:https://www.cnblogs.com/dsliang/p/1769205.html
Copyright © 2011-2022 走看看