List<BoxDataReceive> datas = boxDataReceiveLogic.findTwoTemp(params);
if(datas != null && datas.size()>0){
// 第一步,创建一个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();
style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式
HSSFCell cell = row.createCell((int) 0);
cell.setCellValue("箱号");
cell.setCellStyle(style);
cell = row.createCell((int) 1);
cell.setCellValue("温度");
cell.setCellStyle(style);
cell = row.createCell((int) 2);
cell.setCellValue("湿度");
cell.setCellStyle(style);
cell = row.createCell((int) 3);
cell.setCellValue("温度1");
cell.setCellStyle(style);
cell = row.createCell((int) 4);
cell.setCellValue("湿度1");
cell.setCellStyle(style);
cell = row.createCell((int) 5);
cell.setCellValue("接收时间");
cell.setCellStyle(style);
cell = row.createCell((int) 6);
cell.setCellValue("电量");
cell.setCellStyle(style);
cell = row.createCell((int) 7);
cell.setCellValue("信号");
cell.setCellStyle(style);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
row = sheet.createRow((int) 1);
// 第四步,创建单元格,并设置
for (int i = 0, size = datas.size(); i < size; i++){
row = sheet.createRow((int) i + 1);
BoxDataReceive data = datas.get(i);
row.createCell((int) 0).setCellValue((String)data.getBoxDeviceNumber());
if(data.getTemp()!=null&&!"".equals(data.getTemp())){
row.createCell((int) 1).setCellValue((double) data.getTemp());
}
if(data.getDamp()!=null&&!"".equals(data.getDamp())){
row.createCell((int) 2).setCellValue((double) data.getDamp());
}
if(data.getTemp1()!=null&&!"".equals(data.getTemp1())){
row.createCell((int) 3).setCellValue((double) data.getTemp1());
}
if(data.getDamp1()!=null&&!"".equals(data.getDamp1())){
row.createCell((int) 4).setCellValue((double) data.getDamp1());
}
if(data.getReceiveTime()!=null&&!"".equals(data.getReceiveTime())){
row.createCell((int) 5).setCellValue(sdf.format(data.getReceiveTime()));
}
if(data.getElectricity()!=null){
row.createCell((int) 6).setCellValue((int) data.getElectricity());
}
if(data.getSign()!=null){
row.createCell((int) 7).setCellValue((int) data.getSign());
}
}
sheet.autoSizeColumn((int)0);
sheet.autoSizeColumn((int)1);
sheet.autoSizeColumn((int)2);
sheet.autoSizeColumn((int)3);
sheet.autoSizeColumn((int)4);
sheet.autoSizeColumn((int)5);
sheet.autoSizeColumn((int)6);
sheet.autoSizeColumn((int)7);
// 设置输出的格式
response.reset();
response.setContentType("application/x-msdownload");
response.addHeader("Content-Disposition", "attachment; filename="+boxDeviceNumber+".xls");
wb.write(response.getOutputStream());
response.getOutputStream().flush();
response.getOutputStream().close();
if(datas != null && datas.size()>0){
// 第一步,创建一个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();
style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式
HSSFCell cell = row.createCell((int) 0);
cell.setCellValue("箱号");
cell.setCellStyle(style);
cell = row.createCell((int) 1);
cell.setCellValue("温度");
cell.setCellStyle(style);
cell = row.createCell((int) 2);
cell.setCellValue("湿度");
cell.setCellStyle(style);
cell = row.createCell((int) 3);
cell.setCellValue("温度1");
cell.setCellStyle(style);
cell = row.createCell((int) 4);
cell.setCellValue("湿度1");
cell.setCellStyle(style);
cell = row.createCell((int) 5);
cell.setCellValue("接收时间");
cell.setCellStyle(style);
cell = row.createCell((int) 6);
cell.setCellValue("电量");
cell.setCellStyle(style);
cell = row.createCell((int) 7);
cell.setCellValue("信号");
cell.setCellStyle(style);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
row = sheet.createRow((int) 1);
// 第四步,创建单元格,并设置
for (int i = 0, size = datas.size(); i < size; i++){
row = sheet.createRow((int) i + 1);
BoxDataReceive data = datas.get(i);
row.createCell((int) 0).setCellValue((String)data.getBoxDeviceNumber());
if(data.getTemp()!=null&&!"".equals(data.getTemp())){
row.createCell((int) 1).setCellValue((double) data.getTemp());
}
if(data.getDamp()!=null&&!"".equals(data.getDamp())){
row.createCell((int) 2).setCellValue((double) data.getDamp());
}
if(data.getTemp1()!=null&&!"".equals(data.getTemp1())){
row.createCell((int) 3).setCellValue((double) data.getTemp1());
}
if(data.getDamp1()!=null&&!"".equals(data.getDamp1())){
row.createCell((int) 4).setCellValue((double) data.getDamp1());
}
if(data.getReceiveTime()!=null&&!"".equals(data.getReceiveTime())){
row.createCell((int) 5).setCellValue(sdf.format(data.getReceiveTime()));
}
if(data.getElectricity()!=null){
row.createCell((int) 6).setCellValue((int) data.getElectricity());
}
if(data.getSign()!=null){
row.createCell((int) 7).setCellValue((int) data.getSign());
}
}
sheet.autoSizeColumn((int)0);
sheet.autoSizeColumn((int)1);
sheet.autoSizeColumn((int)2);
sheet.autoSizeColumn((int)3);
sheet.autoSizeColumn((int)4);
sheet.autoSizeColumn((int)5);
sheet.autoSizeColumn((int)6);
sheet.autoSizeColumn((int)7);
// 设置输出的格式
response.reset();
response.setContentType("application/x-msdownload");
response.addHeader("Content-Disposition", "attachment; filename="+boxDeviceNumber+".xls");
wb.write(response.getOutputStream());
response.getOutputStream().flush();
response.getOutputStream().close();