zoukankan      html  css  js  c++  java
  • 使用NPOI 做Excel导出

    1.先去官网:http://npoi.codeplex.com/下载需要引入dll 然后在网站中添加引用。
    2.Asp.Net mvc导出方法
    ///
    <summary> /// 导出Excel /// </summary> /// <returns></returns> public FileResult Excel() { var alist = WishWallServices.QueryWhere(c => c.status == 1).OrderByDescending(c=>c.WishThumbup.Where(q=>q.status==1).Count()).ToList(); //创建Excel文件的对象 NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook(); //添加一个sheet NPOI.SS.UserModel.ISheet sheet1 = book.CreateSheet("心愿墙"); //给sheet添加第一行的头部标题 NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow(0); row1.CreateCell(0).SetCellValue("微信号"); row1.CreateCell(1).SetCellValue("姓名"); row1.CreateCell(2).SetCellValue("心愿标题"); row1.CreateCell(3).SetCellValue("心愿内容"); row1.CreateCell(4).SetCellValue("点赞数"); row1.CreateCell(5).SetCellValue("联系方式"); row1.CreateCell(6).SetCellValue("联系地址"); //....N行 //将数据逐步写入sheet1各个行 for (int i = 0; i < alist.Count; i++) { NPOI.SS.UserModel.IRow rowtemp = sheet1.CreateRow(i + 1); rowtemp.CreateCell(0).SetCellValue(alist[i].WeiXinInfo.WeiXinName); rowtemp.CreateCell(1).SetCellValue(alist[i].name); rowtemp.CreateCell(2).SetCellValue(alist[i].title); rowtemp.CreateCell(3).SetCellValue(alist[i].content); rowtemp.CreateCell(4).SetCellValue(alist[i].WishThumbup.Where(q=>q.status==1).Count()); rowtemp.CreateCell(5).SetCellValue(alist[i].phone); //....N行 } System.IO.MemoryStream ms = new System.IO.MemoryStream(); book.Write(ms); ms.Seek(0, SeekOrigin.Begin); return File(ms, "application/vnd.ms-excel", "心愿墙.xls"); }
  • 相关阅读:
    About DEBUG_NEW
    [bbk5161] 第107集 第13章 表空间管理 05
    [bbk4975] 第103集 第13章 表空间管理 01
    [bbk5156] 第106集 第13章 表空间管理 04
    [bbk4998] 第104集 第13章 表空间管理 02
    [bbk4965] 第102集 第13章 表空间管理 00
    [bbk5119] 第105集 第13章 表空间管理 03
    如何查看表占用空间情况?
    如何手工回收段空间?
    [bbk5162] 第108集 第13章 表空间管理 06
  • 原文地址:https://www.cnblogs.com/MingqiSs/p/7827537.html
Copyright © 2011-2022 走看看