【库房】批量导出Excel表格
发布日期:2021-10-01 22:20:11 浏览次数:16 分类:技术文章

本文共 2657 字,大约阅读时间需要 8 分钟。

前言

有,那必定就有批量导出。

Controller

//添加引用using System.IO;using System.Web.Script.Serialization;using System.Data;using System.Text;using NPOI;using NPOI.HPSF;using NPOI.HSSF;using NPOI.HSSF.UserModel;using NPOI.SS.UserModel; public  void OutoExcel()        {            string title = "仓库信息统计";            NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook();            NPOI.SS.UserModel.ISheet sheet = book.CreateSheet("Sheet1");            NPOI.SS.UserModel.IRow headerrow = sheet.CreateRow(0);            ICellStyle style = book.CreateCellStyle();            style.Alignment = HorizontalAlignment.Center;            style.VerticalAlignment = VerticalAlignment.Center;            #region 设置表格标题,表头            ICell cell = headerrow.CreateCell(0);            cell.CellStyle = style;            cell.SetCellValue("库房编号");            cell = headerrow.CreateCell(1);            cell.CellStyle = style;            cell.SetCellValue("库房名称");            cell = headerrow.CreateCell(2);            cell.CellStyle = style;            cell.SetCellValue("库房位置");            cell = headerrow.CreateCell(3);            cell.CellStyle = style;            cell.SetCellValue("库房面积");            cell = headerrow.CreateCell(4);            cell.CellStyle = style;            cell.SetCellValue("备注");            #endregion            #region 根据标题for循环填充Excel表格            for (int i = 0; i < list.Count; i++)            {                IRow row = sheet.CreateRow(i + 1);                cell = row.CreateCell(0);                cell.SetCellValue(list[i].storageID.ToString());                cell = row.CreateCell(1);                cell.SetCellValue(list[i].storageName.ToString());                cell = row.CreateCell(2);                cell.SetCellValue(list[i].place.ToString());                cell = row.CreateCell(3);                cell.SetCellValue(list[i].capacity.ToString());                cell = row.CreateCell(4);                cell.SetCellValue(list[i].remark.ToString() == "null" ? "" : list[i].remark.ToString());//总是出错,干脆来个空!!!            }            #endregion            #region 弹出导出的界面            MemoryStream ms = new MemoryStream();            book.Write(ms);            Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}.xls", title + "_" + DateTime.Now.ToString("yyyy-MM-dd"), System.Text.Encoding.UTF8));            Response.BinaryWrite(ms.ToArray());            Response.End();            book = null;            ms.Close();            ms.Dispose();            #endregion        }

JS

//导出仓库Excel表格function xport() {
window.location.href = "/Storage/OutoExcel";}

总结

总的来说,批量导出没有批量导入费劲。加油!

转载地址:https://blog.csdn.net/j15533415886/article/details/79215108 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:【库房】查询无数据时如何显示——没有相关记录!
下一篇:【库房】批量导入Excel表格

发表评论

最新留言

关注你微信了!
[***.104.42.241]2024年04月15日 23时25分21秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章

【Leetcode刷题篇】leetcode437 路径总和III 2019-04-26
【Linux篇】Linux常用命令之性能优化 2019-04-26
【面试篇】JVM体系 2019-04-26
【Leetcode刷题篇】leetcode406 根据身高重建队列 2019-04-26
【Leetcode刷题篇】leetcode581 最短无序连续子数组 2019-04-26
【Leetcode刷题篇】leetcode538 把二叉搜索树转换为累加树 2019-04-26
【多线程与高并发】线程的优先级是怎么回事? 2019-04-26
【多线程与高并发】Java守护线程是什么?什么是Java的守护线程? 2019-04-26
【Leetcode刷题篇/面试篇】-前缀树(Trie) 2019-04-26
【Leetcode刷题篇】leetcode337 打家劫舍III 2019-04-26
【Leetcode刷题篇】leetcode4 寻找两个正序数组的中位数 2019-04-26
【Leetcode刷题篇】leetcode316 去除重复字母 2019-04-26
【Leetcode刷题篇】leetcode1081 不同字符的最小子序列 2019-04-26
【面试篇】Java网络编程与IO流体系 2019-04-26
【大话Mysql面试】-Mysql的索引为什么要使用B+树,而不是B树,红黑树等之类? 2019-04-26
【大话Mysql面试】-如何通俗易懂的了解Mysql的索引最左前缀匹配原则 2019-04-26
【大话Mysql面试】-MYSQL的两种存储引擎MyISAM与InnoDB的区别是什么? 2019-04-26
【大话Mysql面试】-InnoDB可重复读隔离级别下如何避免幻读?MVCC和next-key是什么 2019-04-26
【大话Mysql面试】-Mysql如何恢复数据?如何进行主从复制?Binlog日志到底是什么? 2019-04-26
理解String.intern()和String类常量池疑难解析例子 2019-04-26