excel导出
2016-11-23 09:45
106 查看
查询的结果结
List list = commissionMService.getMapper().meishengExport(paramMap);
// 第一步,创建一个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();
sheet.setDefaultColumnWidth(30);
sheet.setColumnWidth(0, 20 * 256);
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);
cell = row.createCell((short) 4);
cell.setCellValue("计划净重");
cell.setCellStyle(style);
遍历结果集填充excel
for(int i =0;i<list.size();i++){
String mission = (String) map.get("MISSION_NO");//委托单号
String pack_code = (String) map.get("PACK_CODE");//出厂计划
String product_id = (String) map.get("PRODUCT_ID");//提单号
String PRODUCT_SHOPSIGN = (String) map.get("PRODUCT_SHOPSIGN");//装区库点
double NET_WEIGHT = 0;
if(StrUtil.isNotNull(map.get("NET_WEIGHT"))){
NET_WEIGHT = Double.parseDouble(map.get("NET_WEIGHT").toString());//计划净重
}
double GROSS_WEIGHT = 0;
if(StrUtil.isNotNull(map.get("GROSS_WEIGHT"))){
NET_WEIGHT = Double.parseDouble(map.get("GROSS_WEIGHT").toString());//毛重
}
double SHEET_COUNTS = 0;
if(StrUtil.isNotNull(map.get("SHEET_COUNTS"))){
NET_WEIGHT = Double.parseDouble(map.get("SHEET_COUNTS").toString());//件数
}
String TRANS_FROM_CONTRACT = (String)map.get("TRANS_FROM_CONTRACT");//固定人
row.createCell((short) 0).setCellValue (mission); //委托单号
row.createCell((short) 1).setCellValue (pack_code); //出厂计划
row.createCell((short) 2).setCellValue (product_id); //提单号
row.createCell((short) 3).setCellValue (PRODUCT_SHOPSIGN); //装区库点
row.createCell((short) 4).setCellValue (NET_WEIGHT); //计划净重
row.createCell((short) 5).setCellValue (GROSS_WEIGHT); //毛重
row.createCell((short) 6).setCellValue (SHEET_COUNTS); //件数
row.createCell((short) 7).setCellValue (TRANS_FROM_CONTRACT); // 固定人
}
最后输出excel
OutputStream os = response.getOutputStream();
wb.write(os);
os.flush();
os.close();
List list = commissionMService.getMapper().meishengExport(paramMap);
// 第一步,创建一个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();
sheet.setDefaultColumnWidth(30);
sheet.setColumnWidth(0, 20 * 256);
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);
cell = row.createCell((short) 4);
cell.setCellValue("计划净重");
cell.setCellStyle(style);
遍历结果集填充excel
for(int i =0;i<list.size();i++){
String mission = (String) map.get("MISSION_NO");//委托单号
String pack_code = (String) map.get("PACK_CODE");//出厂计划
String product_id = (String) map.get("PRODUCT_ID");//提单号
String PRODUCT_SHOPSIGN = (String) map.get("PRODUCT_SHOPSIGN");//装区库点
double NET_WEIGHT = 0;
if(StrUtil.isNotNull(map.get("NET_WEIGHT"))){
NET_WEIGHT = Double.parseDouble(map.get("NET_WEIGHT").toString());//计划净重
}
double GROSS_WEIGHT = 0;
if(StrUtil.isNotNull(map.get("GROSS_WEIGHT"))){
NET_WEIGHT = Double.parseDouble(map.get("GROSS_WEIGHT").toString());//毛重
}
double SHEET_COUNTS = 0;
if(StrUtil.isNotNull(map.get("SHEET_COUNTS"))){
NET_WEIGHT = Double.parseDouble(map.get("SHEET_COUNTS").toString());//件数
}
String TRANS_FROM_CONTRACT = (String)map.get("TRANS_FROM_CONTRACT");//固定人
row.createCell((short) 0).setCellValue (mission); //委托单号
row.createCell((short) 1).setCellValue (pack_code); //出厂计划
row.createCell((short) 2).setCellValue (product_id); //提单号
row.createCell((short) 3).setCellValue (PRODUCT_SHOPSIGN); //装区库点
row.createCell((short) 4).setCellValue (NET_WEIGHT); //计划净重
row.createCell((short) 5).setCellValue (GROSS_WEIGHT); //毛重
row.createCell((short) 6).setCellValue (SHEET_COUNTS); //件数
row.createCell((short) 7).setCellValue (TRANS_FROM_CONTRACT); // 固定人
}
最后输出excel
OutputStream os = response.getOutputStream();
wb.write(os);
os.flush();
os.close();
相关文章推荐
- 使用ADO.net将数据导出到Excel并提供下载
- GridView导出Excel
- mysql笔记七——Java实现excel表的读写(导出mysql数据库的所有表到excel表)
- SQL语句导入导出EXCEL
- 巧用DevExpress GridView导入导出Excel
- springboot easypoi导出excel
- Excel 导出
- [ExtJS5学习笔记]第三十三节 sencha extjs 5 grid表格导出excel
- AspNet GridView Excel 下载 Excel 导出
- 再现C#导出Excel源码
- 表格导出EXCEL
- mysql中数据导出成excel文件语句
- Android sql 数据库的导出到excel中
- .NET导出EXCEL
- asp.net 导出Excel
- 详解thinkphp实现excel数据的导入导出(附完整案例)
- .net解决数据导出excel时的格式问题
- 导出Excel后其他按钮失效
- 关于如何动态导出Excel表格——选择想要导出的字段
- poi导出excel