• 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

  • 相关阅读:
    线性表
    文件IO其四 图片显示
    文件IO其三 目录操作
    文件IO其二 文件IO
    文件IO其一 标准IO
    字符串处理函数
    复杂类型及编译相关
    linux内存分析
    构建根文件系统3-完善根文件系统
    构建根文件系统3-构建最小根文件系统
  • 原文地址:https://www.cnblogs.com/skylaugh/p/409110.html
Copyright © 2020-2023  润新知