下载并导出数据到execl中
下载poi-3.6-20091214.jar。下载地址例如以下:
http://download.csdn.net/detail/evangel_z/3895051
1.jsp
<button type="button" class="btn btn-mini" onClick="location.href='<%=basePath%>/bankcard/exportEffectThirdData?
begintime=${begintime}&endtime=${endtime}&page=1'">导出有效订单</button>
2.后台代码处理:
controller 处理:
@Get("exportReturnThirdData")
public void exportReturnThirdListData(Invocation inv,@Param("begintime") String startTime,
@Param("endtime") String endTime){
HttpServletResponse response = inv.getResponse();
// response.setContentType("application/xls");
response.setContentType("application/x-download");
response.reset();
response.setContentType("bin");
String header = "attachment;filename=returnThirdData.xls";
response.addHeader("Content-Disposition", header);
String[] heads = { "订单日期", "订单号", "商品名称", "商品属性", "渠道名称", "支付银行卡","支付账号", "成本价", "卖出价", "卖出收入", "发货日期", "外订单审核日期", "退货日期", "取消日期" };
List<FenqiGoodsOrder> returnOrders = fenqiGoodsOrderListService
.exportReturnThirdList(startTime, endTime);
String path = "";
OrderDetailExportExeclUtil.exeportListData(heads, returnOrders,response);
}
导出到execl处理逻辑:
public static void exeportListData(String[] heads,List<FenqiGoodsOrder> returnOrders,HttpServletResponse response){
// 第一步。创建一个webbook,相应一个Excel文件
HSSFWorkbook wb = new HSSFWorkbook();
// 第二步。在webbook中加入一个sheet,相应Excel文件里的sheet
HSSFSheet sheet = wb.createSheet("第三方退货订单明细");
// 第三步,在sheet中加入表头第0行,注意老版本号poi对Excel的行数列数有限制short
HSSFRow row = sheet.createRow((int) 0);
// 第四步。创建单元格,并设置值表头 设置表头居中
HSSFCellStyle style = wb.createCellStyle();
style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式
HSSFCell cell=null;
for(int h=0;h<heads.length;h++){
cell = row.createCell((short) h);
cell.setCellValue(heads[h]);
cell.setCellStyle(style);
}
// 第五步,写入实体数据 实际应用中这些数据从数据库得到,
for (int i = 0; i < returnOrders.size(); i++)
{
row = sheet.createRow((int) i + 1);
FenqiGoodsOrder goodsOrder = (FenqiGoodsOrder) returnOrders.get(i);
// 第四步,创建单元格,并设置值
row.createCell((short) 0).setCellValue(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(goodsOrder.getCreateTime()));
row.createCell((short) 1).setCellValue(goodsOrder.getOrderNo());
row.createCell((short) 2).setCellValue(goodsOrder.getGoodName());
row.createCell((short) 3).setCellValue(goodsOrder.getGoodType());
row.createCell((short) 4).setCellValue(goodsOrder.getChannelName());
row.createCell((short) 5).setCellValue(goodsOrder.getCardNo());
row.createCell((short) 6).setCellValue(goodsOrder.getAccountNo());
row.createCell((short) 7).setCellValue(goodsOrder.getPurchasePrice());//成本价
row.createCell((short) 8).setCellValue(goodsOrder.getSellPrice());//卖出价
row.createCell((short) 9).setCellValue(goodsOrder.getSellEarning());//卖出收入
if(goodsOrder.getDeliveryTime() !=null && !goodsOrder.getDeliveryTime().equals("")){
row.createCell((short) 10).setCellValue(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(goodsOrder.getDeliveryTime()));
}
if(goodsOrder.getAuditTime() !=null && !goodsOrder.getAuditTime().equals("")){
row.createCell((short) 11).setCellValue(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(goodsOrder.getAuditTime()));
}
if(goodsOrder.getReturnTime() !=null && !goodsOrder.getReturnTime().equals("")){
row.createCell((short) 12).setCellValue(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(goodsOrder.getReturnTime()));
}
if(goodsOrder.getCancelDate() !=null && !goodsOrder.getCancelDate().equals("")){
row.createCell((short) 13).setCellValue(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(goodsOrder.getCancelDate()));
}
}
// 第六步,将文件存到指定位置
try
{
wb.write(response.getOutputStream());
}
catch (Exception e)
{
e.printStackTrace();
}
}
下载并导出数据到execl中的更多相关文章
- 手把手教你springboot中导出数据到excel中
手把手教你springboot中导出数据到excel中 问题来源: 前一段时间公司的项目有个导出数据的需求,要求能够实现全部导出也可以多选批量导出(虽然不是我负责的,我自己研究了研究),我们的项目是x ...
- MySQL导出数据到文件中的方法
MySQL导出数据到文件中的方法 1.导出数据到txt文件中实例:把数据表studscoreinfo中所有数据导出到指定的位置方法:select * from 表名 into outfile 指定导出 ...
- 1.ASP.NET MVC使用EPPlus,导出数据到Excel中
好久没写博客了,今天特地来更新一下,今天我们要学习的是如何导出数据到Excel文件中,这里我使用的是免费开源的Epplus组件. 源代码下载:https://github.com/caofangshe ...
- 【转】c# winform DataGridView导出数据到Excel中,可以导出当前页和全部数据
准备工作就是可以分页的DataGridView,和两个按钮,一个用来导出当前页数据到Excel,一个用来导出全部数据到Excel 没有使用SaveFileDialog,但却可以弹出保存对话框来 先做导 ...
- 利用NPOI导出数据到Execl
相信很多童鞋都开发过Execl的导入导出功能,最近产品中无论是后台数据分析的需要,还是前端满足用户管理的方便,都有Execl导入导出的维护需求产生. 以前做这个功能,如果是web,利用HttpCont ...
- python 导出数据到excel 中,一个好用的导出数据到excel模块,XlsxWriter
最近公司有项目需要导出数据到excel,首先想到了,tablib,xlwt,xlrd,xlwings,win32com[还可以操作word],openpyxl,等模块但是 实际操作中tablib 写入 ...
- 关于2020.04.26【MySQL导出数据到文件中的方法】的补充
之前导出的数据文件中没有表的列名,感觉不够完整,摸索一下发现带表列名导出也是可以的,只试了导出txt和csv两种文件类型的方法. 1.导出数据到txt文件中(包含数据表列名)的方法:先选择 ...
- C#自定义导出数据到Excel中的类封装
using System; using System.IO; using System.Data; using System.Collections; using System.Data.OleDb; ...
- MySQL导出数据到文件中
一.导出一张表数据 把test_time表中的数据导出成txt 文件 mysql> show global variables like '%secure%'; +--------------- ...
随机推荐
- Codeforces 570D - Tree Requests(树上启发式合并)
570D - Tree Requests 题意 给出一棵树,每个节点上有字母,查询 u k,问以 u 为根节点的子树下,深度为 k 的所有子节点上的字母经过任意排列是否能构成回文串. 分析 一个数组 ...
- Linux文本过滤命令grep、awk、sed
grep的使用: 一.grep一般格式: grep [选项] 基本正则表达式 [文件] 这里的正则表达式可以为字符串.在grep命令中输入字符串参数时,最好将其用双引号括起来.调用变量时也可以使用双引 ...
- 蛋疼的VS2010 tab group
http://superuser.com/questions/232031/why-does-my-visual-studio-2010-default-to-a-horizontal-windows ...
- mybatis学习笔记(六)使用generator生成mybatis基础配置代码和目录结构
原文:http://blog.csdn.net/oh_mourinho/article/details/51463413 创建maven项目 <span style="font-siz ...
- [置顶]
kubernetes资源对象--ResourceQuotas
概念 Resource Quotas(资源配额,简称quota)是对namespace进行资源配额,限制资源使用的一种策略. K8S是一个多用户架构,当多用户或者团队共享一个K8S系统时,SA使用qu ...
- JavaWeb教程路线
主要内容大概例如以下: 1.开发环境搭建 2.servlet/jsp解说 3.mysql解说 4.JDBC解说 5.ssh解说 6.整合开发 7.样例具体解释
- 【Hadoop】Hadoop MR 自定义序列化类
1.基本概念 2.Mapper代码 package com.ares.hadoop.mr.flowsum; import java.io.IOException; import org.apache. ...
- MVC EasyUI 时间格式化
用 return Json(dr, JsonRequestBehavior.AllowGet); 会返回一个json 数据格式,在用 EasyUI 输出表格内容时会遇到时间输出不是我们想要的格式, ...
- 2017.7.10 Package name does not correspond to the file path
参考来自:https://stackoverflow.com/questions/26440623/package-name-does-not-correspond-to-the-file-path- ...
- 【Scala-ML】怎样利用Scala构建并行机器学习系统
引言 在学习Scala的过程中,我发现其在构建大规模分布式计算系统上有与生俱来的特质. 其丰富的类型系统能够帮助编程设计提供非常好的信息隐藏和抽象,其monoids和monads概念利用Scala高阶 ...