将数据导入Excel
/** * 查询未打印订单 * @param req * @param sort * @param order * @param rows * @param page * @return */ public JSONObject queryOrder(HttpServletRequest req,String startDate,String endDate){ Date date = new Date(); DateFormat format = new SimpleDateFormat("yyyy-MM-dd"); String time=format.format(date); //获得当前时间 StringBuffer sql1 = new StringBuffer("select ifnull(u.parentUserCode,'')parentUserCode," + "ifnull(u.siteName,'')siteName,ifnull(e.expressNO,'')expressNO," + "ifnull(date_format(e.takeDate,'%Y-%m-%d %H:%m:%s'),'')takeDate," + "ifnull(date_format(e.enterDate,'%Y-%m-%d %H:%m:%s'),'')enterDate," + "from express e join loginuser u " + "where e.loginUserCode = u.userCode and e.STATUS = 1 "); if((startDate != null && !"".equals(startDate)) && (endDate != null && !"".equals(endDate))){ sql1.append(" and e.takeDate between '"+startDate+"' "+" and "+" '" + endDate+"'"); } else{ sql1.append(" and e.takeDate like '%"+time+"%' "); //导出当前时间的数据 } List<Map<String, Object>> list = jdbcTemplate.queryForList(sql1.toString()); JSONArray array = new JSONArray(); JSONObject obj = new JSONObject(); if(list !=null && list.size()>0){ JSONObject jo = new JSONObject(); for (Map<String, Object> map : list){ jo.put("parentUserCode", map.get("parentUserCode")); jo.put("siteName", map.get("siteName")); jo.put("expressNO", map.get("expressNO")); jo.put("takeDate", map.get("takeDate")); jo.put("enterDate", map.get("enterDate")); array.add(jo); } obj.put("rows", array); }else{ obj.put("rows", null); } return obj; }
/** * 导出未打印订单 * @param req * @param response * @return */ public String exportExcleO(HttpServletRequest req,HttpServletResponse response,String startDate,String endDate){ startDate = req.getParameter("startDate"); endDate = req.getParameter("endDate"); JSONObject jso = queryOrder(req, startDate, endDate); JSONArray json = jso.getJSONArray("rows"); if (json.size()<0 && json==null) { return null; } else { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet("表1"); HSSFRow row = sheet.createRow((int) 0); HSSFCellStyle style = wb.createCellStyle(); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式 HSSFCell cell = row.createCell((short) 0); cell.setCellValue("站点编号"); cell.setCellStyle(style); cell = row.createCell((short) 1); cell.setCellValue("站点名称"); cell.setCellStyle(style); cell = row.createCell((short) 2); cell.setCellValue("接单时间"); cell.setCellStyle(style); cell = row.createCell((short) 3); cell.setCellValue("下单时间"); cell.setCellStyle(style); for (int i = 0; i < json.size(); i++) { JSONObject f = json.getJSONObject(i); row = sheet.createRow((int) i + 1); row.createCell((short) 0).setCellValue(f.getString("parentUserCode")); sheet.setColumnWidth(0, 20 * 200); row.createCell((short) 1).setCellValue(f.getString("siteName")); sheet.setColumnWidth(1, 20 * 300); row.createCell((short) 2).setCellValue(f.getString("takeDate")); sheet.setColumnWidth(2, 20 * 300); row.createCell((short) 3).setCellValue(f.getString("enterDate")); sheet.setColumnWidth(3, 20 * 300); } response.reset(); response.setContentType("application/x-msdownload"); String pName = "未打印订单记录"; try { response.setHeader("Content-Disposition", "attachment; filename=" + new String(pName.getBytes("gb2312"), "ISO-8859-1") + ".xls"); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } ServletOutputStream outStream = null; try { outStream = response.getOutputStream(); wb.write(outStream); } catch (Exception e) { e.printStackTrace(); } finally { try { outStream.close(); } catch (IOException e) { e.printStackTrace(); } } return pName; } }
/*** * 导出未打印订单 */ @RequestMapping(value = "/Orderdownload", method = { RequestMethod.POST, RequestMethod.GET }) @ResponseBody public void exportOrder( @RequestParam("startDate") String startDate, @RequestParam("endDate") String endDate,HttpServletResponse resp,HttpServletRequest req) { nceServiceImpl.exportExcleO(req, resp, startDate, endDate); }
将数据导入Excel的更多相关文章
- [Asp.net]常见数据导入Excel,Excel数据导入数据库解决方案,总有一款适合你!
引言 项目中常用到将数据导入Excel,将Excel中的数据导入数据库的功能,曾经也查找过相关的内容,将曾经用过的方案总结一下. 方案一 NPOI NPOI 是 POI 项目的 .NET 版本.POI ...
- C#变成数据导入Excel和导出Excel
excel 基础 •整个excel 表格叫工作表:workbook:工作表包含的叫页:sheet:行:row:单元格:cell. •excel 中的电话号码问题,看起来像数字的字符串以半角单引号开头就 ...
- 如何将页面上的数据导入excel中
网上关于页面数据导入excel的文章很多,但是大部分都是关于 ActiveXObject 对象,可是ActiveXObject 对象是只支持IE的,可我连IE11也测试了,还是无法识别,又查到消息,好 ...
- C#Winfrom Listview数据导入Excel
需引用 public void ExportToExecl() { System.Windows.Forms.SaveFileDialog sfd = new SaveFileDialog(); sf ...
- 转:[Asp.net]常见数据导入Excel,Excel数据导入数据库解决方案,总有一款适合你!
引言 项目中常用到将数据导入Excel,将Excel中的数据导入数据库的功能,曾经也查找过相关的内容,将曾经用过的方案总结一下. 方案一 NPOI NPOI 是 POI 项目的 .NET 版本.POI ...
- python制作简单excel统计报表3之将mysql数据库中的数据导入excel模板并生成统计图
python制作简单excel统计报表3之将mysql数据库中的数据导入excel模板并生成统计图 # coding=utf-8 from openpyxl import load_workbook ...
- excel数据 入库mysql 和 mysql数据 导入excel文件
1.excel数据入库mysql 首先准备excel文件, 标红的地方需要留意,一个是字段名所在行,一个表名对应页: 然后私用mysql工具 navicat, 选择数据库,然后导入文件, 选中相应ex ...
- Java将数据库数据导入EXCEL
一般的数据库数据怎么导入excel中呢??这让人非常疑惑,今天我找到了一个方法能够实现 须要导入一个第三方包下载地址 详细内容例如以下: 里面含有指导文档,index.html里面含有怎样读取数据库文 ...
- SQLServer外部数据导入--Excel版
例如要在test表里插入多行数据 假设字段有: ID.Name 首先要有需要导入的数据的Excel A1 对应ID B1 对应Name 选中Excel第一行的空白处,比如C1,在工具栏的函数文本框里输 ...
- java数据库数据导入excel
data导出入excel中 controller: package com.longfor.hrssc.api.controller; import com.longfor.hrssc.api.mod ...
随机推荐
- bzoj3223
3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 3700 Solved: 2097[Submit][Sta ...
- BZOJ1257 [CQOI2007]余数之和sum
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...
- strchr()函数 和 strrchr() 函数
strchr 定义于头文件 <string.h>char *strchr( const char *str, int ch );寻找ch(按照如同(char)ch的方式转换成char后)在 ...
- csv 中 数值被自动转换成科学计数法 的问题 excel打开后数字用科学计数法显示且低位变0的解决方法
保存在csv中的 013812345678,前面的0会被去掉,后面是科学计数法显示.保存成 col1,="013812345678" 即可. 注意,分隔符逗号后面直接接“=”等号. ...
- 7 HTML&JS等前端知识系列之jquery的事件绑定
preface 我们知道,每一个a,input等等标签都可以为其绑定一个事件,onclick也好,focus 也罢,都可以绑定的.但是众神key想过这个问题没有,倘若这里有1000个input标签需要 ...
- pip apt source images
~/.pip/pip.conf [global] index-url = https://pypi.douban.com/simple download_cache = ~/.cache/pip [i ...
- [Delphi] Delphi版本号对照
VER300 Delphi Seattle / C++Builder Seattle 23 230 (Delphi:Win32/Win64/OSX/iOS32/iOS64/An ...
- 连接池的实现 redis例子
# -*- encoding:utf-8 -*- # import pymysql # # conn = pymysql.connect(host="127.0.0.1", por ...
- Rss 订阅:php动态生成xml格式的rss文件
Rss 简介: 简易信息聚合(也 叫聚合内容)是一种描述和同步网站内容的格式.使用RSS订阅能更快地获取信息,网站提供RSS输出,有利于让用户获取网站内容的最新更新.网络用户可以在客户端借助于支持RS ...
- LUA 学习笔记
1.C# 与 LUAC#调用LUA比较简单,但LUA调用C#,有两种方法,一种是直接反射调用,但这种方法有局限性,比如性能低,在IOS平台无法使用反射,因此一般使用WARP方法,即把C#代码注册到LU ...