forked from liweijie/education
联教编辑报错
This commit is contained in:
+61
-2
@@ -163,11 +163,70 @@ public class DownloadController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 联教连训管理模板
|
||||
* 联教联训导入模板(动态生成:宋体表头 + 测试样例)。
|
||||
* 列序与 ExcelParseUtil.parseKSBZXMExcel 一致。
|
||||
*/
|
||||
@GetMapping("/joint-training")
|
||||
public void downloadJointTraining(HttpServletResponse response) throws IOException {
|
||||
downloadTemplate(response, "联教连训管理.xls");
|
||||
org.apache.poi.ss.usermodel.Workbook workbook = new org.apache.poi.xssf.usermodel.XSSFWorkbook();
|
||||
try {
|
||||
org.apache.poi.ss.usermodel.Font headerFont = workbook.createFont();
|
||||
headerFont.setFontName("宋体");
|
||||
headerFont.setBold(true);
|
||||
headerFont.setFontHeightInPoints((short) 11);
|
||||
org.apache.poi.ss.usermodel.CellStyle headerStyle = workbook.createCellStyle();
|
||||
headerStyle.setFont(headerFont);
|
||||
|
||||
org.apache.poi.ss.usermodel.Font dataFont = workbook.createFont();
|
||||
dataFont.setFontName("宋体");
|
||||
dataFont.setFontHeightInPoints((short) 11);
|
||||
org.apache.poi.ss.usermodel.CellStyle dataStyle = workbook.createCellStyle();
|
||||
dataStyle.setFont(dataFont);
|
||||
|
||||
String[] headers = {
|
||||
"序号", "补助项目名称", "性质", "依据", "开始日期", "结束日期",
|
||||
"项目说明", "项目备注", "教研室名称", "补助教员姓名", "补助课时量", "课时量备注"
|
||||
};
|
||||
org.apache.poi.ss.usermodel.Sheet sheet = workbook.createSheet("联教联训");
|
||||
org.apache.poi.ss.usermodel.Row headerRow = sheet.createRow(0);
|
||||
for (int i = 0; i < headers.length; i++) {
|
||||
org.apache.poi.ss.usermodel.Cell cell = headerRow.createCell(i);
|
||||
cell.setCellValue(headers[i]);
|
||||
cell.setCellStyle(headerStyle);
|
||||
sheet.setColumnWidth(i, 18 * 256);
|
||||
}
|
||||
|
||||
String[][] samples = {
|
||||
{"1", "联教联训测试项目甲", "集中", "训练计划〔2026〕1号", "2026-03-01", "2026-03-10",
|
||||
"联合教学演练", "导入测试样例1", "战术教研室", "张三", "16", "含备课课时"},
|
||||
{"2", "联教联训测试项目乙", "分散", "训练计划〔2026〕2号", "2026-05-08", "2026-05-20",
|
||||
"跨校区联训", "导入测试样例2", "射击教研室", "李四", "24", ""},
|
||||
{"3", "联教联训测试项目丙", "集中", "训练计划〔2026〕3号", "2026-09-01", "2026-09-15",
|
||||
"联训考核", "导入测试样例3", "指挥教研室", "王五", "12", "按天数核算"}
|
||||
};
|
||||
for (int r = 0; r < samples.length; r++) {
|
||||
org.apache.poi.ss.usermodel.Row row = sheet.createRow(r + 1);
|
||||
for (int c = 0; c < samples[r].length; c++) {
|
||||
org.apache.poi.ss.usermodel.Cell cell = row.createCell(c);
|
||||
cell.setCellValue(samples[r][c]);
|
||||
cell.setCellStyle(dataStyle);
|
||||
}
|
||||
}
|
||||
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
FileUtils.setAttachmentResponseHeader(response, "联教联训数据文件模板.xlsx");
|
||||
workbook.write(response.getOutputStream());
|
||||
response.getOutputStream().flush();
|
||||
} catch (IOException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new ServiceException("生成联教联训导入模板失败:" + e.getMessage());
|
||||
} finally {
|
||||
try {
|
||||
workbook.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user