mvc导出excel 之 新
前段时间做的mvc导出excel
老大说要进行优化,我原来导出是用npoi插件进行导出,格式是将数据放入到datatable中,然后进行导出。
说要优化的时候就想着将datatable数据导出格式改为list集合进行导出效率会好一点
所以就将所有datatable 改为list集合
用datatable 有一个缺点是我在excel显示中的顺序是跟我返回的实体定义的属性的顺序一样的,这样就有点局限性了,想要excel中改变显示顺序就要修改实体中属性的顺序
首先创建excel文件 new hssfworkbook();
创建sheet1 book.createsheet("")
创建row sheet1.createrow(0)
最后给row赋值 row.createcell(0).setcellvalue("")
//创建Excel文件的对象
NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook();
string strdate = DateTime.Now.ToString("yyyyMMddHHmmss");//获取当前时间 if ((orders != null && orders.Count > ) || (bookingorders != null && bookingorders.Count > ))
{
#region sheet1本地数据
//添加一个sheet1 本地的数据导出为excel
NPOI.SS.UserModel.ISheet sheet1 = book.CreateSheet("本地数据");
//给sheet1添加第一行的头部标题
NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow();
if (request.OrderType == "") //挂号
{
row1.CreateCell().SetCellValue("患者ID");
row1.CreateCell().SetCellValue("医院流水号"); //ReturnHisOrderId
row1.CreateCell().SetCellValue("公众服务平台订单号"); //BookOrderId
row1.CreateCell().SetCellValue("支付平台流水号"); // PayOrderId
row1.CreateCell().SetCellValue("退款流水号"); //BookOrderId
//row1.CreateCell(6).SetCellValue("支付平台代码"); //AgtCode
row1.CreateCell().SetCellValue("支付方式"); //paysource
row1.CreateCell().SetCellValue("支付时间"); //PayTime
row1.CreateCell().SetCellValue("支付金额");
row1.CreateCell().SetCellValue("就诊卡号");
row1.CreateCell().SetCellValue("科室");
row1.CreateCell().SetCellValue("医生");
row1.CreateCell().SetCellValue("就诊费用");
row1.CreateCell().SetCellValue("建议就诊时间");
row1.CreateCell().SetCellValue("出诊身份");
row1.CreateCell().SetCellValue("退费");
row1.CreateCell().SetCellValue("退款时间");
for (int i = ; i < bookingorders.Count; i++)
{
NPOI.SS.UserModel.IRow row2 = sheet1.CreateRow(i + );
row2.CreateCell().SetCellValue(bookingorders[i].PatId);
row2.CreateCell().SetCellValue(bookingorders[i].RtnHisOrderId);
row2.CreateCell().SetCellValue(bookingorders[i].BKOrderId);
row2.CreateCell().SetCellValue(bookingorders[i].PayOrderId);
row2.CreateCell().SetCellValue(bookingorders[i].RtnOrderId);
row2.CreateCell().SetCellValue(bookingorders[i].PaySource);
row2.CreateCell().SetCellValue(bookingorders[i].PayTime.ToString());
row2.CreateCell().SetCellValue(bookingorders[i].PayFee.ToString());
row2.CreateCell().SetCellValue(bookingorders[i].VisitingCard);
row2.CreateCell().SetCellValue(bookingorders[i].DeptName);
row2.CreateCell().SetCellValue(bookingorders[i].DoctorName);
row2.CreateCell().SetCellValue(bookingorders[i].ClinicFee.ToString());
row2.CreateCell().SetCellValue(bookingorders[i].AdviceTime);
row2.CreateCell().SetCellValue(bookingorders[i].ClincName);
row2.CreateCell().SetCellValue(bookingorders[i].RtnFee.ToString());
row2.CreateCell().SetCellValue(bookingorders[i].ReturnTime.ToString());
} //将数据逐步写入sheet1各个行
}
else if (request.OrderType == "") //门诊
{
row1.CreateCell().SetCellValue("患者ID");
row1.CreateCell().SetCellValue("医院流水号"); //ReturnHisOrderId
row1.CreateCell().SetCellValue("公众服务平台订单号"); //BookOrderId
row1.CreateCell().SetCellValue("支付平台流水号"); // PayOrderId
row1.CreateCell().SetCellValue("退款账号"); //BookOrderId
row1.CreateCell().SetCellValue("时间"); //paysource
row1.CreateCell().SetCellValue("金额"); //BookOrderId
for (int i = ; i < orders.Count; i++)
{
NPOI.SS.UserModel.IRow row2 = sheet1.CreateRow(i + );
row2.CreateCell().SetCellValue(orders[i].PatientID);
row2.CreateCell().SetCellValue(orders[i].HISReceiptSn);
row2.CreateCell().SetCellValue(orders[i].HisOrderId);
row2.CreateCell().SetCellValue(orders[i].TransactionId);
row2.CreateCell().SetCellValue(orders[i].OutTradeNo);
row2.CreateCell().SetCellValue(orders[i].PayTime.ToString());
row2.CreateCell().SetCellValue(orders[i].HisPayFee);
}
}
mvc导出excel 之 新的更多相关文章
- Mvc 导出 Excel
Mvc 导出 Excel 之前接触过Webform,winfrom 的导出Excel方法 ,优点:省事.缺点:服务器必须安装Office 这几天做项目 和 大牛学习了一下 新的方法,自己加以总结.希望 ...
- ASP.NET MVC导出excel
ASP.NET MVC导出excel 要在ASP.NET MVC站点上做excel导出功能,但是要导出的excel文件比较大,有几十M,所以导出比较费时,为了不影响对界面的其它操作,我就采用异步的方式 ...
- MVC 导出Excel 的其中一方法(View导出excel)
场景:mvc下导出excel 思路:使用View导出excel 步骤: 1.导出标签添加事件 $("#export_A").click(function(){ //省略代码.... ...
- ASP.NET MVC导出excel(数据量大,非常耗时的,异步导出)
要在ASP.NET MVC站点上做excel导出功能,但是要导出的excel文件比较大,有几十M,所以导出比较费时,为了不影响对界面的其它操作,我就采用异步的方式,后台开辟一个线程将excel导出到指 ...
- 三层+MVC导出Excel(2)
背景: 出门在外,一切以健康为主,学习为辅,健康搞好了,学习也不能拉下,在外工作期间,我们在做数据导出的时候,自己封了一个类,利用NPOI进行数据导出Excel,自我感觉良好,特给大家分享一下,希望对 ...
- MVC导出Excel,提供下载Excel
类1: using System.Collections.Generic;using System.Data;using System.Web.Mvc;using System.IO;using Sy ...
- MVC学习笔记---MVC导出excel(数据量大,非常耗时的,异步导出)
要在ASP.NET MVC站点上做excel导出功能,但是要导出的excel文件比较大,有几十M,所以导出比较费时,为了不影响对界面的其它操作,我就采用异步的方式,后台开辟一个线程将excel导出到指 ...
- spring mvc 导出 excel
// js 触发导出 excel 方法 导出当前页的数据 含有条件查询的结果 // js 框架使用的 是 easyui function doExport(){ var optins = $(&quo ...
- mvc导出EXCEL
/// <summary> /// 导出EXCEL /// </summary> /// <returns></returns> public Acti ...
随机推荐
- 模拟微信上传图片(带预览,支持预览gif)
一.Html <style type="text/css"> #previewDiv{width:50px;height:50px;overflow:hidden;po ...
- SQL Server Replication issues-the row was not found at the subscriber end
Issue type: 1.find out the number 0x0006F18F00006082002300000000 from publication end. 2.use below s ...
- 理解HTTP和HTTPS的区别
原问转载于https://www.mysubmail.com/chs/blog/view/47 这两天闲来无事,在网上看了一下,发现 HTTP 和 HTTPS 的区别很受关注,多位大牛做了很详细的阐述 ...
- 搭建IONIC开发环境
1.准备工作 下载 Node.js(下载包),WebStorm(IDE,编写代码,浏览器调试),JDK(webstorm 运行环境),Android SDK (Android编译) 2.配 ...
- 机器学习之决策树熵&信息增量求解算法实现
此文不对理论做相关阐述,仅涉及代码实现: 1.熵计算公式: P为正例,Q为反例 Entropy(S) = PLog2(P) - QLog2(Q); 2.信息增量计算: Gain(S,Sv) = E ...
- C#验证码的生成
HTML <ul> <li>验证码:</li> <li> <img src="/Login/GetValidateCode?ID=1&q ...
- Linux安装脚本需要交互之如何实现自动安装
Linux中shell脚本运行时经常需要进行交互,比如安装软件的过程中对license声明的确认,需要输入yes,回车之类的确认信息.这个在自动化安装的时候就会是个问题. 通常对于这个问题比较灵活的解 ...
- umask
1. 首先我们来思考umask是什么? umask 是系统设置的权限的默认值,在etc/profile里面的shell 脚本有设置规则. 对于root用户和用户而言,不可以直接用的 需要用减法 比如 ...
- shell 转义字符的写法
在链接中,往往会遇到含有‘&'字符的情形,需要转义方能使用. 以下是它的写法样例,错误的写法勿要再犯!! 链接样例: http://my.example.cn/show/details/htd ...
- 在CentOS 6.7中安装NVIDIA GT730显卡驱动的手记
主机: Dell OptiPlex 390 MT (i5) 系列: 主机原配独显,型号未知,运转三年半,常有异响,关机之后过一阵再开机,可以解决.最近,风扇的声音实在不正常,重启也无解,判定它挂了.风 ...