之前一直用Epplus和NPOI做excel处理,这都都不太好用,而且Epplus5.0开始不能商用,aspose.cells挺好用,就是要money,前几天想找替代品,偶然找到国内大神开源的miniexcel,看各种介绍还不错,而且可以避免OOM.
今天在搞asp.net开发excel导出下载遇到个问题,就是要导出多个sheet.就不多废话了,实现代码如下:
var fileName = string.Format("经营财务报表.xlsx");
HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
response.AddHeader("Content-Disposition", string.Format("attachment;filename=\"{0}\"", fileName));
Dictionary<string, object> dict = new Dictionary<string, object>();
dict.Add("费用总表", dt1);
dict.Add("收入", dt2);
dict.Add("支出", dt3);
var memoryStream = new MemoryStream();
memoryStream.SaveAs(dict);
memoryStream.Seek(0, SeekOrigin.Begin);
memoryStream.CopyTo(Response.OutputStream);
response.End();
其中dt1 dt2 dt3是DataTable数据(参考官方给的示例),用字典装载这三个sheet实现多个sheet导出.
以上就是【C#asp.net基于MiniExcel实现多个sheet导出和下载】的全部内容了,欢迎留言评论进行交流!