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);
}

最新文章

  1. javascript原型对象
  2. jQuery.validator 详解二
  3. php函数 date() 详细资料
  4. 面向对象的ExtJS场景开发
  5. 怒学三算法 POJ 2387 Til the Cows Come Home (Bellman_Ford || Dijkstra || SPFA)
  6. mysql 自增序列(转)
  7. ASP.NET 3.5路由总结篇
  8. (九)boost库之文件处理filesystem
  9. Andorid时间控件和日期控件
  10. JS获取随机的16位十六进制的数
  11. LinkedList源码
  12. thinkphp3.2模块名如何不区分大小写?
  13. php5.5之后新特性整理
  14. Python3基础之字典
  15. 微信小程序分享
  16. idea 上搭建 Mybatis 逆向工程
  17. URAL 1635 Mnemonics and Palindromes
  18. AltiumDesigner 热焊盘铺铜
  19. C语言可变参数个数
  20. bzoj 1430: 小猴打架

热门文章

  1. 深入理解Python中的元类(metaclass)
  2. core EFCore 开始尝试
  3. RulersGuides.js – 网站中实现 Photoshop 标尺效果
  4. Linux学习4-信号
  5. 51nod1450 闯关游戏
  6. win7.wifi热点
  7. [LeetCode] #112 #113 #437 Path Sum Series
  8. Treats for the Cows 区间DP POJ 3186
  9. imperva 获取gti文档
  10. Python标准库笔记(9) — functools模块