|
|
|
@ -10,59 +10,41 @@ import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class YunXiaoExportExcelUtil {
|
|
|
|
|
|
|
|
|
|
public void exportToExcel(String filePath, List<Record> list) {
|
|
|
|
|
public void exportToExcel(String filePath, List<Record> list1) {
|
|
|
|
|
try (XSSFWorkbook workbook = new XSSFWorkbook()) {
|
|
|
|
|
XSSFSheet sheet = workbook.createSheet("课程整体");
|
|
|
|
|
//第一个 Sheet
|
|
|
|
|
XSSFSheet sheet1 = workbook.createSheet("整体情况");
|
|
|
|
|
// 创建样式
|
|
|
|
|
CellStyle headerStyle = createHeaderStyle(workbook);
|
|
|
|
|
CellStyle dataStyle = createDataStyle(workbook);
|
|
|
|
|
// 设置列宽
|
|
|
|
|
sheet.setColumnWidth(0, 4000); // 区域
|
|
|
|
|
sheet.setColumnWidth(1, 5000); // 机构编号
|
|
|
|
|
sheet.setColumnWidth(2, 8000); // 机构名称
|
|
|
|
|
sheet.setColumnWidth(3, 4000); // 办学类型
|
|
|
|
|
sheet.setColumnWidth(4, 3000); // 教职工数
|
|
|
|
|
sheet.setColumnWidth(5, 3000); // 专任教师数
|
|
|
|
|
sheet.setColumnWidth(6, 3000); // 班级数
|
|
|
|
|
sheet.setColumnWidth(7, 3000); // 在校生数
|
|
|
|
|
sheet1.setColumnWidth(0, 4000); // 学段
|
|
|
|
|
sheet1.setColumnWidth(1, 8000); // 科目名称
|
|
|
|
|
sheet1.setColumnWidth(2, 5000); // 课程数量
|
|
|
|
|
|
|
|
|
|
// 创建表头
|
|
|
|
|
Row headerRow = sheet.createRow(0);
|
|
|
|
|
Row headerRow = sheet1.createRow(0);
|
|
|
|
|
headerRow.setHeight((short) (28 * 20));
|
|
|
|
|
|
|
|
|
|
String[] headers = {
|
|
|
|
|
"区域", "机构编号", "机构名称", "办学类型",
|
|
|
|
|
"教职工数", "专任教师数", "班级数", "在校生数"
|
|
|
|
|
"学段", "科目名称", "课程数量"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < headers.length; i++) {
|
|
|
|
|
Cell cell = headerRow.createCell(i);
|
|
|
|
|
cell.setCellValue(headers[i]);
|
|
|
|
|
cell.setCellStyle(headerStyle);
|
|
|
|
|
}
|
|
|
|
|
int rowNum = 1;
|
|
|
|
|
|
|
|
|
|
// 填充数据
|
|
|
|
|
for (Record record : list) {
|
|
|
|
|
Row row = sheet.createRow(rowNum++);
|
|
|
|
|
for (Record record : list1) {
|
|
|
|
|
Row row = sheet1.createRow(rowNum++);
|
|
|
|
|
row.setHeight((short) (28 * 20));
|
|
|
|
|
|
|
|
|
|
// 区域
|
|
|
|
|
createCell(row, 0, record.getStr("县区"), dataStyle);
|
|
|
|
|
// 机构编号
|
|
|
|
|
createCell(row, 1, record.getStr("单位号"), dataStyle);
|
|
|
|
|
// 机构名称
|
|
|
|
|
createCell(row, 2, record.getStr("单位名称"), dataStyle);
|
|
|
|
|
// 办学类型
|
|
|
|
|
createCell(row, 3, record.getStr("学校类型"), dataStyle);
|
|
|
|
|
//教职工数
|
|
|
|
|
createCell(row, 4, String.valueOf(record.getInt("教职工数")), dataStyle);
|
|
|
|
|
//专任教师数
|
|
|
|
|
createCell(row, 5, String.valueOf(record.getInt("专任教师数")), dataStyle);
|
|
|
|
|
//班级数
|
|
|
|
|
createCell(row, 6, String.valueOf(record.getInt("班级数")), dataStyle);
|
|
|
|
|
//在校生数
|
|
|
|
|
createCell(row, 7, String.valueOf(record.getInt("在校生数")), dataStyle);
|
|
|
|
|
// 学段
|
|
|
|
|
createCell(row, 0, record.getStr("stage_name"), dataStyle);
|
|
|
|
|
// 科目名称
|
|
|
|
|
createCell(row, 1, record.getStr("subject_name"), dataStyle);
|
|
|
|
|
// 建设数量
|
|
|
|
|
createCell(row, 2, record.getStr("lesson_count"), dataStyle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 保存文件
|
|
|
|
@ -103,23 +85,19 @@ public class YunXiaoExportExcelUtil {
|
|
|
|
|
font.setBold(true);
|
|
|
|
|
font.setFontHeightInPoints((short) 11);
|
|
|
|
|
style.setFont(font);
|
|
|
|
|
|
|
|
|
|
return style;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private CellStyle createDataStyle(XSSFWorkbook workbook) {
|
|
|
|
|
CellStyle style = workbook.createCellStyle();
|
|
|
|
|
|
|
|
|
|
// 设置边框
|
|
|
|
|
style.setBorderTop(BorderStyle.THIN);
|
|
|
|
|
style.setBorderRight(BorderStyle.THIN);
|
|
|
|
|
style.setBorderBottom(BorderStyle.THIN);
|
|
|
|
|
style.setBorderLeft(BorderStyle.THIN);
|
|
|
|
|
|
|
|
|
|
// 设置居中对齐
|
|
|
|
|
style.setAlignment(HorizontalAlignment.CENTER);
|
|
|
|
|
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
|
|
|
|
|
|
|
return style;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|