zoukankan      html  css  js  c++  java
  • DataGrid导出到Word/Excel文档

    将DataGrid数据导出到Word文档

    private void ExportToWord_Click(object sender, System.EventArgs e)
    {
     Response.Clear();
     Response.AddHeader("content-disposition", "attachment;filename=FileName.doc");
     Response.Charset = "";
     Response.Cache.SetCacheability(HttpCacheability.NoCache);
     Response.ContentType = "application/vnd.word";
     System.IO.StringWriter stringWrite = new System.IO.StringWriter();
     System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
     dgDevice.RenderControl(htmlWrite);
     Response.Write(stringWrite.ToString());
     Response.End();
    }

    将DataGrid数据导出到Excel文档

    private void ExportToExcel_Click(object sender, System.EventArgs e)
    {
     Response.Clear();
     Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
     Response.Charset = "";
     Response.Cache.SetCacheability(HttpCacheability.NoCache);
     Response.ContentType = "application/vnd.xls";
     System.IO.StringWriter stringWrite = new System.IO.StringWriter();
     System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
     dgDevice.RenderControl(htmlWrite);
     Response.Write(stringWrite.ToString());
     Response.End();
    }

    本文为codeproject节选,原文地址为:http://www.codeproject.com/aspnet/DAtaGridExportToExcel.asp

  • 相关阅读:
    二叉树
    队列和栈
    时间复杂度和空间复杂度
    二分查找法
    排序算法值归并排序
    排序算法之选择排序类
    5.7.1.3 Global 对象的属性
    5.7.1.2 eval() 方法
    5.7.1.1 单体内置对象
    5.6.3.8 fromCharCode()方法
  • 原文地址:https://www.cnblogs.com/skylaugh/p/409110.html
Copyright © 2011-2022 走看看