zoukankan      html  css  js  c++  java
  • 利用ASP.NET 导出excel(2007版)

    http://www.mikesknowledgebase.com/pages/CSharp/ExportToExcel.htm

    // In this example, I have a defined a List of my Employee objects.
    class Employee;
    List<Employee> listOfEmployees = new List<Employee>();

    ...

    // The following code gets run when I click on my "Export to Excel" button.
    protected void btnExportToExcel_Click(object sender, EventArgs e)
    {
      string filename = "\\\\MikesServer\\ExcelFiles\\Employees.xlsx";
      if (CreateExcelFile.CreateExcelDocument(listOfEmployees, filename))
      {
        // We successfully managed to export to an Excel file.
        // Now, get the ASP.Net application to open this Excel file, ready for the user to view.
        Response.ClearContent();
        FileStream fs1 = new FileStream(filename, FileMode.Open, FileAccess.Read);
        byte[] data1 = new byte[fs1.Length];
        fs1.Read(data1, 0, data1.Length);
      
        Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
        Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", filename));
        Response.BinaryWrite(data1);
        Response.End();
      }
    }

  • 相关阅读:
    字典生成式
    三元表达式
    迭代器
    装饰器
    闭包函数
    名称空间和作用域
    函数嵌套
    SQL Server 影响dbcc checkdb的 8 种因素
    SQL Server 对dbcc checkdb的优化
    SQL Server dbcc checkdb 修复
  • 原文地址:https://www.cnblogs.com/mqingqing123/p/2518074.html
Copyright © 2011-2022 走看看