try {
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("Sheet1");
XSSFRow row = sheet.createRow(0);
XSSFCellStyle style = workbook.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
XSSFCell cell = row.createCell(0);
cell.setCellValue("字段1");
cell.setCellStyle(style);
cell = row.createCell(1);
cell.setCellValue("字段2");
cell.setCellStyle(style);
cell = row.createCell(2);
cell.setCellValue("字段3");
cell.setCellStyle(style);
cell = row.createCell(3);
cell.setCellValue("字段4");
cell.setCellStyle(style);
cell = row.createCell(4);
cell.setCellValue("字段5");
cell.setCellStyle(style);
cell = row.createCell(5);
cell.setCellValue("字段6");
cell.setCellStyle(style);
cell = row.createCell(6);
cell.setCellValue("字段7");
cell.setCellStyle(style);
List<TargetValue> targetValue = targetValueDao.getQuotaValue();
for (int i = 0; i < targetValue.size(); i++) {
row = sheet.createRow(i + 1);
TargetValue stu = targetValues.get(i);
row.createCell(0).setCellValue(stu.getZD1());
row.createCell(1).setCellValue(stu.getZD2());
row.createCell(2).setCellValue(stu.getZD3());
row.createCell(3).setCellValue(stu.getZD4());
row.createCell(4).setCellValue(stu.getZD5());
row.createCell(5).setCellValue("");
row.createCell(6).setCellValue("");
}
OutputStream output = response.getOutputStream();
response.reset();
String fileName = "导入模板";
response.setHeader("Content-disposition", "attachment; filename=" + fileName + ".xlsx");
response.setContentType("application/msexcel");
workbook.write(output);
output.close();
} catch (Exception e) {
}