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 ...
随机推荐
- Name jdbc is not bound in this Context
简介 今天接手中行一个交通罚款web工程时,从svn同步下来后,,启动竟然报找不到数据源错误,本来以为很简单解决找了两个小时,现在记录下来. Exception: Name jdbc is not b ...
- composer 使用详解
1,安装 php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php -r &quo ...
- [Java] 特殊正则-替换字符串
public class Test { public static void main(String[] args) { String str = "2412rhttp://192.168. ...
- arguments.callee的用法
argument为函数内部对象,包含传入函数的所有参数,arguments.callee代表函数名,多用于递归调用,防止函数执行与函数名紧紧耦合的现象,对于没有函数名的匿名函数也非常起作用.举例如下: ...
- js中this的使用
this是Javascript语言的一个关键字. 它代表函数运行时,自动生成的一个内部对象,只能在函数内部使用.比如, function test(){ this.x = 1; } 随着函数使用场合的 ...
- Redis入门学习笔记一
Redis 简要描述: 1. Redis 是啥 ? Redis 英文名称全称为: Remote Dictionary Server ,中译为远程字典服务器. 是一款区分于磁盘数据库如(Mysql)的 ...
- Python’s SQLAlchemy vs Other ORMs[转发 0]
原文地址:http://pythoncentral.io/sqlalchemy-vs-orms/ Overview of Python ORMs As a wonderful language, Py ...
- Scala练习(二)
3.计算指定目录下以".txt"为扩展名的文件个数.注:随便建个目录,建几个.txt文件即可. 4.计算"input_4.txt"文件中搜索词的出现次数,并按次 ...
- javascript 实现tab菜单切换
<!DOCTYPE html> <html> <head> <title></title> </head> <body s ...
- vue-新建项目出错情况分析
1.状况一: 按照正常流程新建项目,最终运行npm run dev 的时候,就频频出错,最终找出问题原来在于部分依赖包丢失了,于是重新安装所需要的依赖包再运行项目便好了!