PackagePlanEntity packagePlanEntity = packagePlanDao.selectById(id);
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFFont createFont = workbook.createFont();
createFont.setFontHeightInPoints((short) 12);// 设置字体
XSSFCellStyle cellStyle = workbook.createCellStyle();
cellStyle.setAlignment(HorizontalAlignment.LEFT); // 内容居左
cellStyle.setFont(createFont);
XSSFCellStyle cellStyle1 = workbook.createCellStyle();
cellStyle1.setAlignment(HorizontalAlignment.CENTER);// 水平居中
cellStyle1.setFont(createFont);
cellStyle1.setVerticalAlignment(VerticalAlignment.CENTER); //上下居中
XSSFSheet sheet = workbook.createSheet("组装计划列表");
//获取行
XSSFRow row0 = sheet.createRow(0);
String[] title = {"组装计划名称","组装计划说明","组装计划创建时间","发送状态","组装计划创建人","组装计划办理人","组装计划抄送人"};
for (int i = 0; i < title.length; i++) {
XSSFCell title0 = row0.createCell(i);
title0.setCellValue(title[i]);
if(i==7){
sheet.setColumnWidth(i, 8000);//物料名称一列
}else{
sheet.setColumnWidth(i, 4500);
}
title0.setCellStyle(cellStyle1);
}
XSSFRow row1 = sheet.createRow(1);
XSSFCell cell0 = row1.createCell(0);
cell0.setCellValue(packagePlanEntity.getPackagePlanName());
cell0.setCellStyle(cellStyle1);
XSSFCell cell1 = row1.createCell(1);
cell1.setCellValue(packagePlanEntity.getPackagePlanExplain());
cell1.setCellStyle(cellStyle1);
DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date createAt = packagePlanEntity.getCreateAt();
String format1 = format.format(createAt);
XSSFCell cell2 = row1.createCell(2);
cell2.setCellValue(format1);
cell2.setCellStyle(cellStyle1);
//下载
ServletOutputStream fileOut = null;
try {
fileOut = response.getOutputStream();
String fileName = new String("组装计划列表".getBytes("UTF-8"), "ISO8859-1");
response.addHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls");
fileOut = response.getOutputStream();
workbook.write(fileOut);
} catch (Exception e1) {
e1.printStackTrace();
} finally {
if (fileOut != null) {
try {
fileOut.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
}
poi 导出 实例
最新推荐文章于 2023-08-03 11:26:00 发布