zoukankan      html  css  js  c++  java
  • asp.net using library ClosedXML to export excel

    Reference:  http://closedxml.codeplex.com/ 

    1. First add refenrence ClosedXML.dll and DocumentFormat.OpenXml.dll to the project. 

    2. add namespace: 

    using ClosedXML.Excel;
    using System.IO;




    3. Method:

    public void ExportDataToExcel(DataTable dt, string fileName)
    		{
    			using (XLWorkbook wb = new XLWorkbook())
    			{
     
    				var ws = wb.Worksheets.Add(dt, "ws");  // worksheets name must be added. 
    				wb.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
    				wb.Style.Font.Bold = true;
     
    				//set header style
    				ws.Rows(1, 1).Style.Fill.BackgroundColor = XLColor.White;
    				ws.Rows(1, 1).Style.Font.Bold = true;
    				ws.Rows(1, 1).Style.Font.FontColor = XLColor.Onyx;
    				ws.Columns().Width = 20;
     
    				//remove AutoFilter
    				ws.Tables.FirstOrDefault().ShowAutoFilter = false;
    				
     
    				Response.Clear();
    				Response.Buffer = true;
    				Response.Charset = "utf-8";
    				Response.ContentType = "application/vnd.ms-excel";
    				Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx");
     
    				using (MemoryStream MyMemoryStream = new MemoryStream())
    				{
    					wb.SaveAs(MyMemoryStream);
    					MyMemoryStream.WriteTo(Response.OutputStream);
    					Response.Flush();
    					Response.End();
    				}
    			}
    		}

  • 相关阅读:
    进程(二)
    操作系统简介-计算机历史、进程(一)
    MemCahce For Java
    fiddler:工具栏介绍
    fiddler相关
    HTTP:Cookie
    在eclipse中开发servlet流程
    servlet 开发入门&生命周期
    HTTP响应
    HTTP:请求头信息
  • 原文地址:https://www.cnblogs.com/facial/p/5142832.html
Copyright © 2011-2022 走看看