asp.net下简单的Epplus导出excel

引用的命名空间

using System.IO;

using OfficeOpenXml;

/// <summary>
/// 导出excel
/// </summary>
/// <param name="context"></param>
/// <param name="fileName"></param>
public void exportExcel(HttpContext context,string fileName)
{
ExcelPackage ep = new ExcelPackage();
ExcelWorkbook wb = ep.Workbook;
ExcelWorksheet ws = wb.Worksheets.Add("helloworld");
ws.Cells["A1"].Value = "hello world";
FileInfo file = new FileInfo(fileName);
ep.SaveAs(file);
}

使用exportExcel函数

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string path= Server.MapPath("~/excel");
exportExcel(Context, path + "\test.xlsx");

}
}

EPPlus详细使用情况可参考:http://epplus.codeplex.com/SourceControl/latest

原文地址:https://www.cnblogs.com/ForeverSoft/p/3627785.html