|
@@ -15,11 +15,14 @@ import cn.com.qmth.stmms.ms.core.vo.Subject;
|
|
|
import com.google.gson.Gson;
|
|
|
import org.apache.commons.lang.math.NumberUtils;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
|
|
|
-import org.apache.poi.hssf.usermodel.HSSFRow;
|
|
|
-import org.apache.poi.hssf.usermodel.HSSFSheet;
|
|
|
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
|
+import org.apache.poi.ss.usermodel.CellStyle;
|
|
|
+import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
|
|
+import org.apache.poi.ss.usermodel.VerticalAlignment;
|
|
|
import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
+import org.apache.poi.xssf.streaming.SXSSFRow;
|
|
|
+import org.apache.poi.xssf.streaming.SXSSFSheet;
|
|
|
+import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
@@ -132,7 +135,7 @@ public class ScoreExporter {
|
|
|
* @param index
|
|
|
* @return
|
|
|
*/
|
|
|
- public void drawExcelTeacher(int type, Map<String, ExportLevelResultDTO> map, HSSFSheet sheet, HSSFCellStyle style, HSSFRow row, AtomicInteger index) {
|
|
|
+ public void drawExcelTeacher(int type, Map<String, ExportLevelResultDTO> map, SXSSFSheet sheet, CellStyle style, SXSSFRow row, AtomicInteger index) {
|
|
|
map.forEach((k, v) -> {
|
|
|
drawExcelFixedHead(sheet, style, row, new HeaderNode(String.valueOf(v.getTeacherName()) + TEACHER, 1, 1, index.get(), index.get()));
|
|
|
v.setFirstCol(index.get());
|
|
@@ -158,12 +161,12 @@ public class ScoreExporter {
|
|
|
* @param row
|
|
|
* @return
|
|
|
*/
|
|
|
- public HSSFSheet drawExcelFixedHead(HSSFSheet sheet, HSSFCellStyle style, HSSFRow row, HeaderNode headerNode) {
|
|
|
+ public SXSSFSheet drawExcelFixedHead(SXSSFSheet sheet, CellStyle style, SXSSFRow row, HeaderNode headerNode) {
|
|
|
Cell cell = row.createCell(headerNode.getFirstCol());
|
|
|
cell.setCellValue(headerNode.getName());
|
|
|
cell.setCellStyle(style);
|
|
|
- CellRangeAddress region = new CellRangeAddress(headerNode.getFirstRow(), headerNode.getLastRow(), (short) headerNode.getFirstCol(), (short) headerNode.getLastCol());
|
|
|
- sheet.addMergedRegion(region);
|
|
|
+// CellRangeAddress region = new CellRangeAddress(headerNode.getFirstRow(), headerNode.getLastRow(), (short) headerNode.getFirstCol(), (short) headerNode.getLastCol());
|
|
|
+// sheet.addMergedRegionUnsafe(region);
|
|
|
return sheet;
|
|
|
}
|
|
|
|
|
@@ -176,33 +179,33 @@ public class ScoreExporter {
|
|
|
* @param row
|
|
|
* @param subjectMap
|
|
|
*/
|
|
|
- public HSSFSheet drawExcelFixedHead(int type, HSSFSheet sheet, HSSFCellStyle style, HSSFRow row, Map<String, Map<String, ExportLevelResultDTO>> subjectMap) {
|
|
|
+ public SXSSFSheet drawExcelFixedHead(int type, SXSSFSheet sheet, CellStyle style, SXSSFRow row, Map<String, Map<String, ExportLevelResultDTO>> subjectMap) {
|
|
|
//准考证号
|
|
|
Cell cell = row.createCell(0);
|
|
|
cell.setCellValue(EXAM_NUMBER);
|
|
|
cell.setCellStyle(style);
|
|
|
CellRangeAddress region1 = new CellRangeAddress(0, 1, (short) 0, (short) 0);
|
|
|
- sheet.addMergedRegion(region1);
|
|
|
+ sheet.addMergedRegionUnsafe(region1);
|
|
|
sheet.setColumnWidth(0, 15 * 256);
|
|
|
//姓名
|
|
|
Cell cell1 = row.createCell(1);
|
|
|
cell1.setCellValue(NAME);
|
|
|
cell1.setCellStyle(style);
|
|
|
CellRangeAddress region2 = new CellRangeAddress(0, 1, (short) 1, (short) 1);
|
|
|
- sheet.addMergedRegion(region2);
|
|
|
+ sheet.addMergedRegionUnsafe(region2);
|
|
|
//考区
|
|
|
Cell cell2 = row.createCell(2);
|
|
|
cell2.setCellValue(AREA_NAME);
|
|
|
cell2.setCellStyle(style);
|
|
|
CellRangeAddress region3 = new CellRangeAddress(0, 1, (short) 2, (short) 2);
|
|
|
- sheet.addMergedRegion(region3);
|
|
|
+ sheet.addMergedRegionUnsafe(region3);
|
|
|
sheet.setColumnWidth(2, 30 * 256);
|
|
|
//生源地
|
|
|
Cell cell3 = row.createCell(3);
|
|
|
cell3.setCellValue(SOURCE_NAME);
|
|
|
cell3.setCellStyle(style);
|
|
|
CellRangeAddress region4 = new CellRangeAddress(0, 1, (short) 3, (short) 3);
|
|
|
- sheet.addMergedRegion(region4);
|
|
|
+ sheet.addMergedRegionUnsafe(region4);
|
|
|
//色彩
|
|
|
int size = 0;
|
|
|
if (Objects.nonNull(subjectMap.get(Subject.SC.toString()))) {
|
|
@@ -217,8 +220,10 @@ public class ScoreExporter {
|
|
|
Cell cell4 = row.createCell(level);
|
|
|
cell4.setCellValue(SC_NAME);
|
|
|
cell4.setCellStyle(style);
|
|
|
- CellRangeAddress region5 = new CellRangeAddress(0, 0, (short) level, scSumCount);
|
|
|
- sheet.addMergedRegion(region5);
|
|
|
+ if (level != scSumCount) {
|
|
|
+ CellRangeAddress region5 = new CellRangeAddress(0, 0, (short) level, scSumCount);
|
|
|
+ sheet.addMergedRegionUnsafe(region5);
|
|
|
+ }
|
|
|
LOGGER.info("level:{},scSumCount:{}", level, scSumCount);
|
|
|
|
|
|
//素描
|
|
@@ -236,8 +241,10 @@ public class ScoreExporter {
|
|
|
Cell cell5 = row.createCell(scSumCount);
|
|
|
cell5.setCellValue(SM_NAME);
|
|
|
cell5.setCellStyle(style);
|
|
|
- CellRangeAddress region6 = new CellRangeAddress(0, 0, (short) scSumCount, smSumCount);
|
|
|
- sheet.addMergedRegion(region6);
|
|
|
+ if (scSumCount != smSumCount) {
|
|
|
+ CellRangeAddress region6 = new CellRangeAddress(0, 0, (short) scSumCount, smSumCount);
|
|
|
+ sheet.addMergedRegionUnsafe(region6);
|
|
|
+ }
|
|
|
LOGGER.info("scSumCount:{},smSumCount:{}", scSumCount, smSumCount);
|
|
|
//速写
|
|
|
smSumCount = smSumCount + 1;//起始列+1
|
|
@@ -254,8 +261,10 @@ public class ScoreExporter {
|
|
|
Cell cell6 = row.createCell(smSumCount);
|
|
|
cell6.setCellValue(SX_NAME);
|
|
|
cell6.setCellStyle(style);
|
|
|
- CellRangeAddress region7 = new CellRangeAddress(0, 0, (short) smSumCount, sxSumCount);
|
|
|
- sheet.addMergedRegion(region7);
|
|
|
+ if (smSumCount != sxSumCount) {
|
|
|
+ CellRangeAddress region7 = new CellRangeAddress(0, 0, (short) smSumCount, sxSumCount);
|
|
|
+ sheet.addMergedRegionUnsafe(region7);
|
|
|
+ }
|
|
|
LOGGER.info("smSumCount:{},sxSumCount:{}", smSumCount, sxSumCount);
|
|
|
return sheet;
|
|
|
}
|
|
@@ -288,18 +297,18 @@ public class ScoreExporter {
|
|
|
assembleData(list, subjectMap, studentAnswerMap, exportLevelResultDTOs);
|
|
|
|
|
|
//创建excel
|
|
|
- HSSFWorkbook wb = new HSSFWorkbook();
|
|
|
- HSSFSheet sheet = wb.createSheet(LEVEL_FILE_NAME);
|
|
|
- HSSFCellStyle style = wb.createCellStyle();
|
|
|
- style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 水平居中格式
|
|
|
- style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); //垂直居中
|
|
|
- HSSFRow row = sheet.createRow(0);
|
|
|
+ SXSSFWorkbook wb = new SXSSFWorkbook();
|
|
|
+ SXSSFSheet sheet = wb.createSheet(LEVEL_FILE_NAME);
|
|
|
+ CellStyle style = wb.createCellStyle();
|
|
|
+ style.setAlignment(HorizontalAlignment.CENTER);// 左右居中
|
|
|
+ style.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ SXSSFRow row = sheet.createRow(0);
|
|
|
|
|
|
//绘制固定表头
|
|
|
sheet = drawExcelFixedHead(levelInterval, sheet, style, row, subjectMap);
|
|
|
|
|
|
//绘制动态表头
|
|
|
- HSSFRow dynamicHeadRow = sheet.createRow(1);
|
|
|
+ SXSSFRow dynamicHeadRow = sheet.createRow(1);
|
|
|
//SC表头
|
|
|
Map<String, ExportLevelResultDTO> scMap = subjectMap.get(Subject.SC.toString());
|
|
|
int size = 0;
|
|
@@ -320,13 +329,13 @@ public class ScoreExporter {
|
|
|
}
|
|
|
//加载excel数据
|
|
|
AtomicInteger cellIndex = new AtomicInteger(0);
|
|
|
- HSSFSheet finalSheet = sheet;
|
|
|
+ SXSSFSheet finalSheet = sheet;
|
|
|
AtomicInteger i = new AtomicInteger(0);
|
|
|
AtomicInteger r = new AtomicInteger(2);
|
|
|
exportLevelResultDTOs.forEach((listk, listv) -> {
|
|
|
int firstRow = i.get() + r.get();
|
|
|
cellIndex.set(0);
|
|
|
- HSSFRow hssfRow = finalSheet.createRow(firstRow);
|
|
|
+ SXSSFRow hssfRow = finalSheet.createRow(firstRow);
|
|
|
drawExcelFixedHead(finalSheet, style, hssfRow, new HeaderNode(listv.getExamNumber(), firstRow, firstRow, cellIndex.get(), cellIndex.get()));
|
|
|
cellIndex.getAndIncrement();
|
|
|
drawExcelFixedHead(finalSheet, style, hssfRow, new HeaderNode(listv.getStudentName(), firstRow, firstRow, cellIndex.get(), cellIndex.get()));
|
|
@@ -402,18 +411,18 @@ public class ScoreExporter {
|
|
|
assembleData(list, subjectMap, studentAnswerMap, exportLevelResultDTOs);
|
|
|
|
|
|
//创建excel
|
|
|
- HSSFWorkbook wb = new HSSFWorkbook();
|
|
|
- HSSFSheet sheet = wb.createSheet(SCORE_FILE_NAME);
|
|
|
- HSSFCellStyle style = wb.createCellStyle();
|
|
|
- style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 水平居中格式
|
|
|
- style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); //垂直居中
|
|
|
- HSSFRow row = sheet.createRow(0);
|
|
|
+ SXSSFWorkbook wb = new SXSSFWorkbook();
|
|
|
+ SXSSFSheet sheet = wb.createSheet(SCORE_FILE_NAME);
|
|
|
+ CellStyle style = wb.createCellStyle();
|
|
|
+ style.setAlignment(HorizontalAlignment.CENTER);// 左右居中
|
|
|
+ style.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ SXSSFRow row = sheet.createRow(0);
|
|
|
|
|
|
//绘制固定表头
|
|
|
sheet = drawExcelFixedHead(scoreInterval, sheet, style, row, subjectMap);
|
|
|
|
|
|
//绘制动态表头
|
|
|
- HSSFRow dynamicHeadRow = sheet.createRow(1);
|
|
|
+ SXSSFRow dynamicHeadRow = sheet.createRow(1);
|
|
|
//SC表头
|
|
|
Map<String, ExportLevelResultDTO> scMap = subjectMap.get(Subject.SC.toString());
|
|
|
int size = 0;
|
|
@@ -434,13 +443,13 @@ public class ScoreExporter {
|
|
|
}
|
|
|
//加载excel数据
|
|
|
AtomicInteger cellIndex = new AtomicInteger(0);
|
|
|
- HSSFSheet finalSheet = sheet;
|
|
|
+ SXSSFSheet finalSheet = sheet;
|
|
|
AtomicInteger i = new AtomicInteger(0);
|
|
|
AtomicInteger r = new AtomicInteger(2);
|
|
|
exportLevelResultDTOs.forEach((listk, listv) -> {
|
|
|
int firstRow = i.get() + r.get();
|
|
|
cellIndex.set(0);
|
|
|
- HSSFRow hssfRow = finalSheet.createRow(firstRow);
|
|
|
+ SXSSFRow hssfRow = finalSheet.createRow(firstRow);
|
|
|
drawExcelFixedHead(finalSheet, style, hssfRow, new HeaderNode(listv.getExamNumber(), firstRow, firstRow, cellIndex.get(), cellIndex.get()));
|
|
|
cellIndex.getAndIncrement();
|
|
|
drawExcelFixedHead(finalSheet, style, hssfRow, new HeaderNode(listv.getStudentName(), firstRow, firstRow, cellIndex.get(), cellIndex.get()));
|