1.下载Epplus. http://epplus.codeplex.com/
2.添加引用Epplus.dll.
protected void Button1_Click(object sender, EventArgs e)
{
OfficeOpenXml.ExcelPackage ep = new OfficeOpenXml.ExcelPackage();
OfficeOpenXml.ExcelWorkbook wb = ep.Workbook;
OfficeOpenXml.ExcelWorksheet ws = wb.Worksheets.Add("我的工作表");
//配置文件属性
wb.Properties.Category = "类别";
wb.Properties.Author = "作者";
wb.Properties.Comments = "备注";
wb.Properties.Company = "公司";
wb.Properties.Keywords = "关键字";
wb.Properties.Manager = "管理者";
wb.Properties.Status = "内容状态";
wb.Properties.Subject = "主题";
wb.Properties.Title = "标题";
wb.Properties.LastModifiedBy = "最后一次保存者";
//写数据
ws.Cells[1, 1].Value = "Hello";
ws.Column(1).width=40;//修改列宽
ws.Cells["B1"].Value = "World";
ws.Cells[3, 3, 3, 5].Merge = true;
ws.Cells[3, 3].Value = "Cells[3, 3, 3, 5]合并";
ws.Cells["A4:D5"].Merge = true;
ws.Cells["A4"].Value = "Cells[\"A4:D5\"]合并";
//写到客户端(下载)
Response.Clear();
Response.AddHeader("content-disposition", "attachment; filename=FileFlow.xls");
Response.ContentType ="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.BinaryWrite(ep.GetAsByteArray());
//ep.SaveAs(Response.OutputStream); 第二种方式
Response.Flush();
Response.End();
}