将数据导入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 ...
随机推荐
- 多线程之异步编程: 经典和最新的异步编程模型, IAsyncInfo 与 Task 相互转换
经典的异步编程模型(IAsyncResult) 最新的异步编程模型(async 和 await) 将 IAsyncInfo 转换成 Task 将 Task 转换成 IAsyncInfo 示例1.使用经 ...
- Linux系统编程:基本I/O系统调用
文件描述符 进程每打开一个文件的时候,会获得该文件的文件描述符,而后续的读写操作都把文件描述符作为参数.在用户空间或者内核空间,都是通过文件描述符来唯一地索引一个打开的文件.文件描述符使用int类型表 ...
- 小猪cms命名规则整理
1.模板命名规则: 类名+函数名称+.html 2.Model命名规则: 数据库表名:cms_user_data 文件名称命名: UserDataModel.class.php <?php cl ...
- android GPS定位源码 地图显示位置源码 有用到的小伙伴自提取
package com.jasgroup.cn.amhdeam; import java.io.IOException; import java.util.Iterator; import andro ...
- css 文字超出部分显示省略号(原)
单行超出省略号 #word1{width: 100px; text-overflow: ellipsis; overflow: hidden;} 几行超出省略号(只兼容webkit内核) #wordN ...
- Cookie和Session的区别
前言 HTTP是一种无状态的协议,为了分辨链接是谁发起的,就需要我们自己去解决这个问题.不然有些情况下即使是同一个网站我们每打开一个页面也都要登录一下.而Session和Cookie就是为解决这个问题 ...
- DOM解析XML报错:Content is not allowed in prolog
报错内容为: Content is not allowed in prolog. Nested exception: Content is not allowed in prolog. 网上所述总结来 ...
- mybatis generator.xml 配置 自动生成model,dao,mapping
generator.xml文件: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE gener ...
- 【转载】如何用IntelliJ IDEA 14 创建Web项目
首先要理解一个概念:在IntelliJ IDEA中"new Project"相当于eclipse中的工作空间(Workspace),而"new Module"相 ...
- RabbitMQ学习系列(四): 几种Exchange 模式
上一篇,讲了RabbitMQ的具体用法,可以看看这篇文章:RabbitMQ学习系列(三): C# 如何使用 RabbitMQ.今天说些理论的东西,Exchange 的几种模式. AMQP协议中的核心思 ...