Asp.net MVC NPOI导出Excel
2024-08-31 22:54:14
public class NpoiMemoryStream : MemoryStream
{
public NpoiMemoryStream()
{
AllowClose = true;
} public bool AllowClose { get; set; } public override void Close()
{
if (AllowClose)
base.Close();
}
}
public ActionResult Export()
{
int orderId = base.Id; Orders order = OrdersModel.GetInstance.GetById(orderId); var workbook = new XSSFWorkbook(Server.MapPath("~/Template/order.xlsx"));
var sheet = workbook.GetSheetAt(); IRow row = sheet.CreateRow();
row.CreateCell().SetCellValue("货号");
row.CreateCell().SetCellValue("品名");
row.CreateCell().SetCellValue("颜色"); string fname = string.Format("{0}.xlsx", order.OrderNo); //导出Excel文件的方法
var ms = new NpoiMemoryStream();
ms.AllowClose = false;
workbook.Write(ms);
ms.Flush();
ms.Seek(, SeekOrigin.Begin);
ms.AllowClose = true;
return File(ms, "application/vnd.ms-excel", fname);
}
最新文章
- javascript原型对象
- jQuery.validator 详解二
- php函数 date() 详细资料
- 面向对象的ExtJS场景开发
- 怒学三算法 POJ 2387 Til the Cows Come Home (Bellman_Ford || Dijkstra || SPFA)
- mysql 自增序列(转)
- ASP.NET 3.5路由总结篇
- (九)boost库之文件处理filesystem
- Andorid时间控件和日期控件
- JS获取随机的16位十六进制的数
- LinkedList源码
- thinkphp3.2模块名如何不区分大小写?
- php5.5之后新特性整理
- Python3基础之字典
- 微信小程序分享
- idea 上搭建 Mybatis 逆向工程
- URAL 1635 Mnemonics and Palindromes
- AltiumDesigner 热焊盘铺铜
- C语言可变参数个数
- bzoj 1430: 小猴打架