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"); }
  • 相关阅读:
    redis-LinkedList
    Jedis(java操作redis数据库技术)
    jquery判断表单内容是否为空
    jQuery单选框的回显
    使用jQuery重置(reset)表单的方法
    BootstrapValidator 解决多属性被同时校验问题
    模态框被遮罩层遮挡
    python 高阶函数
    python 函数式编程
    python 生成器
  • 原文地址:https://www.cnblogs.com/MingqiSs/p/7827537.html
Copyright © 2011-2022 走看看