查询的结果结

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();

 

 posted on 2016-07-21 10:03  她叫我李先生  阅读(134)  评论(0编辑  收藏  举报