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