将数据导入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 ...
随机推荐
- git 提交代码
git config --global user.name=a_name git config --global user.email=an_email_address mkdir test cd t ...
- 【原】聊一聊 url 编码问题
最近项目中遇到需要编码的一个问题,在encode和encodeURIComponent上绕了个小圈,所以打算总结一下js的编码问题,网上也有很多类似的文章,不过呢,总结出来的东西才是自己滴 为什么需要 ...
- RSA加密例子和中途遇到的问题
在进行RSA加密例子 package test; import java.io.IOException; import java.security.Key; import java.security. ...
- easyUI combobox 控件 使用
1,combobox 二级联动 (参数传递 函数调用) // toolbar 学校班级二级联动 var paramSearch = { school : $('#search-school'), cl ...
- Web Map Gis 开发系列索引
Google Map API Version3 :代码添加和删除marker标记 谷歌地图地理解析和反解析geocode.geocoder详解 Google map markers 百度与谷歌地图瓦片 ...
- laydate兼容bootstrap
因为Bootstrap使用了 * {box-sizing:border-box;}来reset浏览器的默认盒子模型.所以加上以下代码就可以兼容Bootstrap了 <style type=&qu ...
- oracle根据某个字段去重实例
if not object_id('Tempdb..#T') is null drop table #T Go Create table #T([ID] int,[Name] nvarchar(1), ...
- vtkPlane和vtkPlaneSource
1.vtkPlane vtkPlane provides methods for various plane computations. These include projecting points ...
- JPA入门
JPA是什么 JPA全称Java Persistence API,是一组用于将数据存入数据库的类和方法的集合.JPA通过JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化 ...
- WPF程序将DLL嵌入到EXE的两种方法
WPF程序将DLL嵌入到EXE的两种方法 这一篇可以看作是<Visual Studio 版本转换工具WPF版开源了>的续,关于<Visual Studio 版本转换工具WPF版开源了 ...