|
@@ -11,6 +11,7 @@ import cn.com.qmth.examcloud.core.questions.service.temp.vo.DdExcelDto;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.temp.vo.DdPaperDto;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.temp.vo.DdPaperStructDto;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.temp.vo.SubQuestionDto;
|
|
|
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
@@ -25,6 +26,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
import java.io.OutputStream;
|
|
|
import java.util.*;
|
|
|
|
|
@@ -60,7 +62,7 @@ public class DdExcelService {
|
|
|
//查询所有课程
|
|
|
long startCourseTime = System.currentTimeMillis();
|
|
|
//List<Course> courses = courseRepo.findByOrgId(orgId);
|
|
|
- List<Course> courses = new ArrayList<Course>();
|
|
|
+ List<Course> courses = new ArrayList<>();
|
|
|
long endCourseTime = System.currentTimeMillis();
|
|
|
log.debug("查询课程耗时:" + (endCourseTime - startCourseTime) + "ms");
|
|
|
if (courses != null && courses.size() > 0) {
|
|
@@ -140,7 +142,7 @@ public class DdExcelService {
|
|
|
* 导出按大题名称统计分布
|
|
|
*/
|
|
|
@SuppressWarnings("resource")
|
|
|
- public void exporExcel(String orgId) throws Exception {
|
|
|
+ public void exporExcel(String orgId) {
|
|
|
//导出Excel集合
|
|
|
List<DdExcelDto> ddExcelDtos = new ArrayList<>();
|
|
|
//查询所有课程
|
|
@@ -186,199 +188,209 @@ public class DdExcelService {
|
|
|
i++;
|
|
|
}
|
|
|
}
|
|
|
- Map<String, Long> otherMap = new HashMap<>();
|
|
|
+
|
|
|
//生成Excel对象
|
|
|
File ddExcelFile = new File(exportExcelPath);
|
|
|
- Workbook workBook = new XSSFWorkbook(ddExcelFile);
|
|
|
- //获取第一个工作页
|
|
|
- Sheet sheet = workBook.getSheetAt(0);
|
|
|
- log.debug(sheet.getSheetName());
|
|
|
- //向Excle中写入数据,从第2行开始
|
|
|
- for (int i = 0; i < ddExcelDtos.size(); i++) {
|
|
|
- //创建一行:从第1行开始,跳过表头
|
|
|
- Row row = sheet.createRow(i + 1);
|
|
|
- DdExcelDto ddExcelDto = ddExcelDtos.get(i);
|
|
|
- //每列赋值
|
|
|
- row.createCell(0).setCellValue(ddExcelDto.getCourseName());
|
|
|
- row.createCell(1).setCellValue(ddExcelDto.getCourseCode());
|
|
|
- if (ddExcelDto.getMap() != null && ddExcelDto.getMap().size() > 0) {
|
|
|
- if (ddExcelDto.getMap().get("单选题") == null) {
|
|
|
- row.createCell(2).setCellValue(0);
|
|
|
- } else {
|
|
|
- row.createCell(2).setCellValue(ddExcelDto.getMap().get("单选题"));
|
|
|
- }
|
|
|
+ File file = new File(xianExcelPath);
|
|
|
|
|
|
- if (ddExcelDto.getMap().get("多选题") == null) {
|
|
|
- row.createCell(3).setCellValue(0);
|
|
|
- } else {
|
|
|
- row.createCell(3).setCellValue(ddExcelDto.getMap().get("多选题"));
|
|
|
- }
|
|
|
+ try (Workbook workBook = new XSSFWorkbook(ddExcelFile);
|
|
|
+ OutputStream out = new FileOutputStream(file);) {
|
|
|
+
|
|
|
+ //获取第一个工作页
|
|
|
+ Sheet sheet = workBook.getSheetAt(0);
|
|
|
+ log.debug(sheet.getSheetName());
|
|
|
+
|
|
|
+ //向Excel中写入数据,从第2行开始
|
|
|
+ for (int i = 0; i < ddExcelDtos.size(); i++) {
|
|
|
+ //创建一行:从第1行开始,跳过表头
|
|
|
+ Row row = sheet.createRow(i + 1);
|
|
|
+ DdExcelDto ddExcelDto = ddExcelDtos.get(i);
|
|
|
+ //每列赋值
|
|
|
+ row.createCell(0).setCellValue(ddExcelDto.getCourseName());
|
|
|
+ row.createCell(1).setCellValue(ddExcelDto.getCourseCode());
|
|
|
+
|
|
|
+ if (ddExcelDto.getMap() != null && ddExcelDto.getMap().size() > 0) {
|
|
|
+ if (ddExcelDto.getMap().get("单选题") == null) {
|
|
|
+ row.createCell(2).setCellValue(0);
|
|
|
+ } else {
|
|
|
+ row.createCell(2).setCellValue(ddExcelDto.getMap().get("单选题"));
|
|
|
+ }
|
|
|
|
|
|
- if (ddExcelDto.getMap().get("填空题") == null) {
|
|
|
- row.createCell(4).setCellValue(0);
|
|
|
- } else {
|
|
|
- row.createCell(4).setCellValue(ddExcelDto.getMap().get("填空题"));
|
|
|
- }
|
|
|
+ if (ddExcelDto.getMap().get("多选题") == null) {
|
|
|
+ row.createCell(3).setCellValue(0);
|
|
|
+ } else {
|
|
|
+ row.createCell(3).setCellValue(ddExcelDto.getMap().get("多选题"));
|
|
|
+ }
|
|
|
|
|
|
- if (ddExcelDto.getMap().get("选词填空") == null) {
|
|
|
- row.createCell(5).setCellValue(0);
|
|
|
- } else {
|
|
|
- row.createCell(5).setCellValue(ddExcelDto.getMap().get("选词填空"));
|
|
|
- }
|
|
|
+ if (ddExcelDto.getMap().get("填空题") == null) {
|
|
|
+ row.createCell(4).setCellValue(0);
|
|
|
+ } else {
|
|
|
+ row.createCell(4).setCellValue(ddExcelDto.getMap().get("填空题"));
|
|
|
+ }
|
|
|
|
|
|
- if (ddExcelDto.getMap().get("完型填空") == null) {
|
|
|
- row.createCell(6).setCellValue(0);
|
|
|
- } else {
|
|
|
- row.createCell(6).setCellValue(ddExcelDto.getMap().get("完型填空"));
|
|
|
- }
|
|
|
+ if (ddExcelDto.getMap().get("选词填空") == null) {
|
|
|
+ row.createCell(5).setCellValue(0);
|
|
|
+ } else {
|
|
|
+ row.createCell(5).setCellValue(ddExcelDto.getMap().get("选词填空"));
|
|
|
+ }
|
|
|
|
|
|
- if (ddExcelDto.getMap().get("判断题") == null) {
|
|
|
- row.createCell(7).setCellValue(0);
|
|
|
- } else {
|
|
|
- row.createCell(7).setCellValue(ddExcelDto.getMap().get("判断题"));
|
|
|
- }
|
|
|
+ if (ddExcelDto.getMap().get("完型填空") == null) {
|
|
|
+ row.createCell(6).setCellValue(0);
|
|
|
+ } else {
|
|
|
+ row.createCell(6).setCellValue(ddExcelDto.getMap().get("完型填空"));
|
|
|
+ }
|
|
|
|
|
|
- if (ddExcelDto.getMap().get("阅读理解") == null) {
|
|
|
- row.createCell(8).setCellValue(0);
|
|
|
- } else {
|
|
|
- row.createCell(8).setCellValue(ddExcelDto.getMap().get("阅读理解"));
|
|
|
- }
|
|
|
+ if (ddExcelDto.getMap().get("判断题") == null) {
|
|
|
+ row.createCell(7).setCellValue(0);
|
|
|
+ } else {
|
|
|
+ row.createCell(7).setCellValue(ddExcelDto.getMap().get("判断题"));
|
|
|
+ }
|
|
|
|
|
|
- if (ddExcelDto.getMap().get("问答题") == null) {
|
|
|
- row.createCell(9).setCellValue(0);
|
|
|
- } else {
|
|
|
- row.createCell(9).setCellValue(ddExcelDto.getMap().get("问答题"));
|
|
|
- }
|
|
|
+ if (ddExcelDto.getMap().get("阅读理解") == null) {
|
|
|
+ row.createCell(8).setCellValue(0);
|
|
|
+ } else {
|
|
|
+ row.createCell(8).setCellValue(ddExcelDto.getMap().get("阅读理解"));
|
|
|
+ }
|
|
|
|
|
|
- if (ddExcelDto.getMap().get("名词解释") == null) {
|
|
|
- row.createCell(10).setCellValue(0);
|
|
|
- } else {
|
|
|
- row.createCell(10).setCellValue(ddExcelDto.getMap().get("名词解释"));
|
|
|
- }
|
|
|
+ if (ddExcelDto.getMap().get("问答题") == null) {
|
|
|
+ row.createCell(9).setCellValue(0);
|
|
|
+ } else {
|
|
|
+ row.createCell(9).setCellValue(ddExcelDto.getMap().get("问答题"));
|
|
|
+ }
|
|
|
|
|
|
- //额外大题名称
|
|
|
- if (ddExcelDto.getMap().get("案例分析") == null) {
|
|
|
- row.createCell(11).setCellValue(0);
|
|
|
- } else {
|
|
|
- row.createCell(11).setCellValue(ddExcelDto.getMap().get("案例分析"));
|
|
|
- }
|
|
|
+ if (ddExcelDto.getMap().get("名词解释") == null) {
|
|
|
+ row.createCell(10).setCellValue(0);
|
|
|
+ } else {
|
|
|
+ row.createCell(10).setCellValue(ddExcelDto.getMap().get("名词解释"));
|
|
|
+ }
|
|
|
|
|
|
- if (ddExcelDto.getMap().get("作文题") == null) {
|
|
|
- row.createCell(12).setCellValue(0);
|
|
|
- } else {
|
|
|
- row.createCell(12).setCellValue(ddExcelDto.getMap().get("作文题"));
|
|
|
- }
|
|
|
+ //额外大题名称
|
|
|
+ if (ddExcelDto.getMap().get("案例分析") == null) {
|
|
|
+ row.createCell(11).setCellValue(0);
|
|
|
+ } else {
|
|
|
+ row.createCell(11).setCellValue(ddExcelDto.getMap().get("案例分析"));
|
|
|
+ }
|
|
|
|
|
|
- if (ddExcelDto.getMap().get("交际英语") == null) {
|
|
|
- row.createCell(13).setCellValue(0);
|
|
|
- } else {
|
|
|
- row.createCell(13).setCellValue(ddExcelDto.getMap().get("交际英语"));
|
|
|
- }
|
|
|
+ if (ddExcelDto.getMap().get("作文题") == null) {
|
|
|
+ row.createCell(12).setCellValue(0);
|
|
|
+ } else {
|
|
|
+ row.createCell(12).setCellValue(ddExcelDto.getMap().get("作文题"));
|
|
|
+ }
|
|
|
|
|
|
- if (ddExcelDto.getMap().get("简答题") == null) {
|
|
|
- row.createCell(14).setCellValue(0);
|
|
|
- } else {
|
|
|
- row.createCell(14).setCellValue(ddExcelDto.getMap().get("简答题"));
|
|
|
- }
|
|
|
+ if (ddExcelDto.getMap().get("交际英语") == null) {
|
|
|
+ row.createCell(13).setCellValue(0);
|
|
|
+ } else {
|
|
|
+ row.createCell(13).setCellValue(ddExcelDto.getMap().get("交际英语"));
|
|
|
+ }
|
|
|
|
|
|
- if (ddExcelDto.getMap().get("一、单选题") == null) {
|
|
|
- row.createCell(15).setCellValue(0);
|
|
|
- } else {
|
|
|
- row.createCell(15).setCellValue(ddExcelDto.getMap().get("一、单选题"));
|
|
|
- }
|
|
|
+ if (ddExcelDto.getMap().get("简答题") == null) {
|
|
|
+ row.createCell(14).setCellValue(0);
|
|
|
+ } else {
|
|
|
+ row.createCell(14).setCellValue(ddExcelDto.getMap().get("简答题"));
|
|
|
+ }
|
|
|
|
|
|
- if (ddExcelDto.getMap().get("名称解释") == null) {
|
|
|
- row.createCell(16).setCellValue(0);
|
|
|
- } else {
|
|
|
- row.createCell(16).setCellValue(ddExcelDto.getMap().get("名称解释"));
|
|
|
- }
|
|
|
+ if (ddExcelDto.getMap().get("一、单选题") == null) {
|
|
|
+ row.createCell(15).setCellValue(0);
|
|
|
+ } else {
|
|
|
+ row.createCell(15).setCellValue(ddExcelDto.getMap().get("一、单选题"));
|
|
|
+ }
|
|
|
|
|
|
- if (ddExcelDto.getMap().get("综合题") == null) {
|
|
|
- row.createCell(17).setCellValue(0);
|
|
|
- } else {
|
|
|
- row.createCell(17).setCellValue(ddExcelDto.getMap().get("综合题"));
|
|
|
- }
|
|
|
+ if (ddExcelDto.getMap().get("名称解释") == null) {
|
|
|
+ row.createCell(16).setCellValue(0);
|
|
|
+ } else {
|
|
|
+ row.createCell(16).setCellValue(ddExcelDto.getMap().get("名称解释"));
|
|
|
+ }
|
|
|
|
|
|
- if (ddExcelDto.getMap().get("设计题") == null) {
|
|
|
- row.createCell(18).setCellValue(0);
|
|
|
- } else {
|
|
|
- row.createCell(18).setCellValue(ddExcelDto.getMap().get("设计题"));
|
|
|
- }
|
|
|
+ if (ddExcelDto.getMap().get("综合题") == null) {
|
|
|
+ row.createCell(17).setCellValue(0);
|
|
|
+ } else {
|
|
|
+ row.createCell(17).setCellValue(ddExcelDto.getMap().get("综合题"));
|
|
|
+ }
|
|
|
|
|
|
- if (ddExcelDto.getMap().get("二、名词解释") == null) {
|
|
|
- row.createCell(19).setCellValue(0);
|
|
|
- } else {
|
|
|
- row.createCell(19).setCellValue(ddExcelDto.getMap().get("二、名词解释"));
|
|
|
- }
|
|
|
+ if (ddExcelDto.getMap().get("设计题") == null) {
|
|
|
+ row.createCell(18).setCellValue(0);
|
|
|
+ } else {
|
|
|
+ row.createCell(18).setCellValue(ddExcelDto.getMap().get("设计题"));
|
|
|
+ }
|
|
|
|
|
|
- if (ddExcelDto.getMap().get("分析题") == null) {
|
|
|
- row.createCell(20).setCellValue(0);
|
|
|
- } else {
|
|
|
- row.createCell(20).setCellValue(ddExcelDto.getMap().get("分析题"));
|
|
|
- }
|
|
|
+ if (ddExcelDto.getMap().get("二、名词解释") == null) {
|
|
|
+ row.createCell(19).setCellValue(0);
|
|
|
+ } else {
|
|
|
+ row.createCell(19).setCellValue(ddExcelDto.getMap().get("二、名词解释"));
|
|
|
+ }
|
|
|
|
|
|
- if (ddExcelDto.getMap().get("英汉翻译") == null) {
|
|
|
- row.createCell(21).setCellValue(0);
|
|
|
- } else {
|
|
|
- row.createCell(21).setCellValue(ddExcelDto.getMap().get("英汉翻译"));
|
|
|
- }
|
|
|
+ if (ddExcelDto.getMap().get("分析题") == null) {
|
|
|
+ row.createCell(20).setCellValue(0);
|
|
|
+ } else {
|
|
|
+ row.createCell(20).setCellValue(ddExcelDto.getMap().get("分析题"));
|
|
|
+ }
|
|
|
|
|
|
- if (ddExcelDto.getMap().get("作文") == null) {
|
|
|
- row.createCell(22).setCellValue(0);
|
|
|
- } else {
|
|
|
- row.createCell(22).setCellValue(ddExcelDto.getMap().get("作文"));
|
|
|
- }
|
|
|
+ if (ddExcelDto.getMap().get("英汉翻译") == null) {
|
|
|
+ row.createCell(21).setCellValue(0);
|
|
|
+ } else {
|
|
|
+ row.createCell(21).setCellValue(ddExcelDto.getMap().get("英汉翻译"));
|
|
|
+ }
|
|
|
|
|
|
- if (ddExcelDto.getMap().get("二、计算题") == null) {
|
|
|
- row.createCell(23).setCellValue(0);
|
|
|
- } else {
|
|
|
- row.createCell(23).setCellValue(ddExcelDto.getMap().get("二、计算题"));
|
|
|
- }
|
|
|
+ if (ddExcelDto.getMap().get("作文") == null) {
|
|
|
+ row.createCell(22).setCellValue(0);
|
|
|
+ } else {
|
|
|
+ row.createCell(22).setCellValue(ddExcelDto.getMap().get("作文"));
|
|
|
+ }
|
|
|
|
|
|
- if (ddExcelDto.getMap().get("作图题") == null) {
|
|
|
- row.createCell(24).setCellValue(0);
|
|
|
- } else {
|
|
|
- row.createCell(24).setCellValue(ddExcelDto.getMap().get("作图题"));
|
|
|
- }
|
|
|
+ if (ddExcelDto.getMap().get("二、计算题") == null) {
|
|
|
+ row.createCell(23).setCellValue(0);
|
|
|
+ } else {
|
|
|
+ row.createCell(23).setCellValue(ddExcelDto.getMap().get("二、计算题"));
|
|
|
+ }
|
|
|
|
|
|
- if (ddExcelDto.getMap().get("论述题") == null) {
|
|
|
- row.createCell(25).setCellValue(0);
|
|
|
- } else {
|
|
|
- row.createCell(25).setCellValue(ddExcelDto.getMap().get("论述题"));
|
|
|
- }
|
|
|
+ if (ddExcelDto.getMap().get("作图题") == null) {
|
|
|
+ row.createCell(24).setCellValue(0);
|
|
|
+ } else {
|
|
|
+ row.createCell(24).setCellValue(ddExcelDto.getMap().get("作图题"));
|
|
|
+ }
|
|
|
|
|
|
- if (ddExcelDto.getMap().get("三、计算题") == null) {
|
|
|
- row.createCell(26).setCellValue(0);
|
|
|
- } else {
|
|
|
- row.createCell(26).setCellValue(ddExcelDto.getMap().get("三、计算题"));
|
|
|
- }
|
|
|
+ if (ddExcelDto.getMap().get("论述题") == null) {
|
|
|
+ row.createCell(25).setCellValue(0);
|
|
|
+ } else {
|
|
|
+ row.createCell(25).setCellValue(ddExcelDto.getMap().get("论述题"));
|
|
|
+ }
|
|
|
|
|
|
- if (ddExcelDto.getMap().get("计算题") == null) {
|
|
|
- row.createCell(27).setCellValue(0);
|
|
|
- } else {
|
|
|
- row.createCell(27).setCellValue(ddExcelDto.getMap().get("计算题"));
|
|
|
- }
|
|
|
+ if (ddExcelDto.getMap().get("三、计算题") == null) {
|
|
|
+ row.createCell(26).setCellValue(0);
|
|
|
+ } else {
|
|
|
+ row.createCell(26).setCellValue(ddExcelDto.getMap().get("三、计算题"));
|
|
|
+ }
|
|
|
|
|
|
- if (ddExcelDto.getMap().get("算法设计题") == null) {
|
|
|
- row.createCell(28).setCellValue(0);
|
|
|
- } else {
|
|
|
- row.createCell(28).setCellValue(ddExcelDto.getMap().get("算法设计题"));
|
|
|
- }
|
|
|
+ if (ddExcelDto.getMap().get("计算题") == null) {
|
|
|
+ row.createCell(27).setCellValue(0);
|
|
|
+ } else {
|
|
|
+ row.createCell(27).setCellValue(ddExcelDto.getMap().get("计算题"));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ddExcelDto.getMap().get("算法设计题") == null) {
|
|
|
+ row.createCell(28).setCellValue(0);
|
|
|
+ } else {
|
|
|
+ row.createCell(28).setCellValue(ddExcelDto.getMap().get("算法设计题"));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ddExcelDto.getMap().get("翻译题") == null) {
|
|
|
+ row.createCell(29).setCellValue(0);
|
|
|
+ } else {
|
|
|
+ row.createCell(29).setCellValue(ddExcelDto.getMap().get("翻译题"));
|
|
|
+ }
|
|
|
|
|
|
- if (ddExcelDto.getMap().get("翻译题") == null) {
|
|
|
- row.createCell(29).setCellValue(0);
|
|
|
} else {
|
|
|
- row.createCell(29).setCellValue(ddExcelDto.getMap().get("翻译题"));
|
|
|
+ log.debug("课程:" + ddExcelDto.getCourseName());
|
|
|
}
|
|
|
-
|
|
|
- } else {
|
|
|
- log.debug("课程:" + ddExcelDto.getCourseName());
|
|
|
}
|
|
|
+
|
|
|
+ workBook.write(out);
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ } catch (InvalidFormatException e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
}
|
|
|
- File file = new File(xianExcelPath);
|
|
|
- OutputStream out = new FileOutputStream(file);
|
|
|
- workBook.write(out);
|
|
|
- out.close();
|
|
|
+
|
|
|
log.debug("结束...");
|
|
|
}
|
|
|
|
|
@@ -389,7 +401,7 @@ public class DdExcelService {
|
|
|
public void exportPaperExcel(String orgId) throws Exception {
|
|
|
log.debug("开始导出试卷具体信息。。。。");
|
|
|
//导出Excel对象集合
|
|
|
- List<DdPaperDto> excelDtoList = new ArrayList<DdPaperDto>();
|
|
|
+ List<DdPaperDto> excelDtoList = new ArrayList<>();
|
|
|
//根据课程查询试卷
|
|
|
Query query = new Query();
|
|
|
query.addCriteria(Criteria.where("orgId").is(orgId));
|
|
@@ -454,27 +466,37 @@ public class DdExcelService {
|
|
|
i++;
|
|
|
}
|
|
|
}*/
|
|
|
+
|
|
|
//生成Excel对象
|
|
|
File ddExcelFile = new File(paperExcelPath);
|
|
|
- Workbook workBook = new XSSFWorkbook(ddExcelFile);
|
|
|
- //获取第一个工作页
|
|
|
- Sheet sheet = workBook.getSheetAt(0);
|
|
|
- //向Excle中写入数据,从第2行开始
|
|
|
- for (int i = 0; i < excelDtoList.size(); i++) {
|
|
|
- //创建一行:从第1行开始,跳过表头
|
|
|
- Row row = sheet.createRow(i + 1);
|
|
|
- DdPaperDto excelDto = excelDtoList.get(i);
|
|
|
- //每列赋值
|
|
|
- row.createCell(0).setCellValue(excelDto.getCode());
|
|
|
- row.createCell(1).setCellValue(excelDto.getName());
|
|
|
- row.createCell(2).setCellValue(excelDto.getPaperName());
|
|
|
- row.createCell(3).setCellValue(excelDto.getDetailName());
|
|
|
- row.createCell(4).setCellValue(excelDto.getNumber());
|
|
|
- }
|
|
|
File file = new File(paperExcelPathNew);
|
|
|
- OutputStream out = new FileOutputStream(file);
|
|
|
- workBook.write(out);
|
|
|
- out.close();
|
|
|
+
|
|
|
+ try (Workbook workBook = new XSSFWorkbook(ddExcelFile);
|
|
|
+ OutputStream out = new FileOutputStream(file);) {
|
|
|
+
|
|
|
+ //获取第一个工作页
|
|
|
+ Sheet sheet = workBook.getSheetAt(0);
|
|
|
+
|
|
|
+ //向Excel中写入数据,从第2行开始
|
|
|
+ for (int i = 0; i < excelDtoList.size(); i++) {
|
|
|
+ //创建一行:从第1行开始,跳过表头
|
|
|
+ Row row = sheet.createRow(i + 1);
|
|
|
+ DdPaperDto excelDto = excelDtoList.get(i);
|
|
|
+ //每列赋值
|
|
|
+ row.createCell(0).setCellValue(excelDto.getCode());
|
|
|
+ row.createCell(1).setCellValue(excelDto.getName());
|
|
|
+ row.createCell(2).setCellValue(excelDto.getPaperName());
|
|
|
+ row.createCell(3).setCellValue(excelDto.getDetailName());
|
|
|
+ row.createCell(4).setCellValue(excelDto.getNumber());
|
|
|
+ }
|
|
|
+
|
|
|
+ workBook.write(out);
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ } catch (InvalidFormatException e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ }
|
|
|
+
|
|
|
log.debug("结束...");
|
|
|
}
|
|
|
|
|
@@ -488,7 +510,7 @@ public class DdExcelService {
|
|
|
List<DdPaperStructDto> excelDtoList = new ArrayList<>();
|
|
|
//查询所有课程
|
|
|
List<Course> courses = courseRepo.findByOrgId(orgId);
|
|
|
- //List<Course> courses = new ArrayList<Course>();
|
|
|
+ //List<Course> courses = new ArrayList<>();
|
|
|
log.debug("查询课程总数:" + courses.size());
|
|
|
|
|
|
if (courses != null && courses.size() > 0) {
|
|
@@ -529,28 +551,38 @@ public class DdExcelService {
|
|
|
i++;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
//生成Excel对象
|
|
|
File ddExcelFile = new File(paperStructExcelPath);
|
|
|
- Workbook workBook = new XSSFWorkbook(ddExcelFile);
|
|
|
- //获取第一个工作页
|
|
|
- Sheet sheet = workBook.getSheetAt(0);
|
|
|
- //向Excle中写入数据,从第2行开始
|
|
|
- for (int i = 0; i < excelDtoList.size(); i++) {
|
|
|
- //创建一行:从第1行开始,跳过表头
|
|
|
- Row row = sheet.createRow(i + 1);
|
|
|
- DdPaperStructDto excelDto = excelDtoList.get(i);
|
|
|
- //每列赋值
|
|
|
- row.createCell(0).setCellValue(excelDto.getCode());
|
|
|
- row.createCell(1).setCellValue(excelDto.getName());
|
|
|
- row.createCell(2).setCellValue(excelDto.getDetailName());
|
|
|
- row.createCell(3).setCellValue(excelDto.getQuesNames());
|
|
|
- row.createCell(4).setCellValue(excelDto.getNumber());
|
|
|
- row.createCell(5).setCellValue(excelDto.getQuesType());
|
|
|
- }
|
|
|
File file = new File(paperStructExcelPathNew);
|
|
|
- OutputStream out = new FileOutputStream(file);
|
|
|
- workBook.write(out);
|
|
|
- out.close();
|
|
|
+
|
|
|
+ try (Workbook workBook = new XSSFWorkbook(ddExcelFile);
|
|
|
+ OutputStream out = new FileOutputStream(file);) {
|
|
|
+
|
|
|
+ //获取第一个工作页
|
|
|
+ Sheet sheet = workBook.getSheetAt(0);
|
|
|
+
|
|
|
+ //向Excel中写入数据,从第2行开始
|
|
|
+ for (int i = 0; i < excelDtoList.size(); i++) {
|
|
|
+ //创建一行:从第1行开始,跳过表头
|
|
|
+ Row row = sheet.createRow(i + 1);
|
|
|
+ DdPaperStructDto excelDto = excelDtoList.get(i);
|
|
|
+ //每列赋值
|
|
|
+ row.createCell(0).setCellValue(excelDto.getCode());
|
|
|
+ row.createCell(1).setCellValue(excelDto.getName());
|
|
|
+ row.createCell(2).setCellValue(excelDto.getDetailName());
|
|
|
+ row.createCell(3).setCellValue(excelDto.getQuesNames());
|
|
|
+ row.createCell(4).setCellValue(excelDto.getNumber());
|
|
|
+ row.createCell(5).setCellValue(excelDto.getQuesType());
|
|
|
+ }
|
|
|
+
|
|
|
+ workBook.write(out);
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ } catch (InvalidFormatException e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ }
|
|
|
+
|
|
|
log.debug("结束...");
|
|
|
}
|
|
|
|
|
@@ -625,52 +657,60 @@ public class DdExcelService {
|
|
|
|
|
|
//生成Excel对象
|
|
|
File ddExcelFile = new File(quesExcelPath);
|
|
|
- Workbook workBook = new XSSFWorkbook(ddExcelFile);
|
|
|
- //获取第一个工作页
|
|
|
- Sheet sheet = workBook.getSheetAt(0);
|
|
|
-
|
|
|
- //标题
|
|
|
- Row titleRow = sheet.createRow(0);
|
|
|
- titleRow.createCell(0).setCellValue("课程代码");
|
|
|
- titleRow.createCell(1).setCellValue("课程名称");
|
|
|
- titleRow.createCell(2).setCellValue("试卷名称");
|
|
|
- titleRow.createCell(3).setCellValue("原始试卷ID");
|
|
|
- titleRow.createCell(4).setCellValue("大题号");
|
|
|
- titleRow.createCell(5).setCellValue("小题号");
|
|
|
- titleRow.createCell(6).setCellValue("标准分");
|
|
|
- titleRow.createCell(7).setCellValue("大题名称");
|
|
|
- titleRow.createCell(8).setCellValue("题干");
|
|
|
- titleRow.createCell(9).setCellValue("题干(含标签)");
|
|
|
- titleRow.createCell(10).setCellValue("标答");
|
|
|
- titleRow.createCell(11).setCellValue("标答(含标签)");
|
|
|
-
|
|
|
- //向Excle中写入数据,从第2行开始
|
|
|
- for (int i = 0; i < subjectQuestions.size(); i++) {
|
|
|
- //创建一行:从第1行开始,跳过表头
|
|
|
- Row row = sheet.createRow(i + 1);
|
|
|
- SubQuestionDto dto = subjectQuestions.get(i);
|
|
|
- //每列赋值
|
|
|
- row.createCell(0).setCellValue(dto.getCourseCode());
|
|
|
- row.createCell(1).setCellValue(dto.getCourseName());
|
|
|
- row.createCell(2).setCellValue(dto.getPaperName());
|
|
|
- row.createCell(3).setCellValue(dto.getPaperId());
|
|
|
- row.createCell(4).setCellValue(dto.getdNumber());
|
|
|
- row.createCell(5).setCellValue(dto.getNumber());
|
|
|
- row.createCell(6).setCellValue(dto.getScore());
|
|
|
- row.createCell(7).setCellValue(dto.getDetailName());
|
|
|
- row.createCell(8).setCellValue(dto.getClearBody());
|
|
|
- row.createCell(9).setCellValue(dto.getBody());
|
|
|
- if (dto.getClearAnswer().length() < 32767) {
|
|
|
- row.createCell(10).setCellValue(dto.getClearAnswer());
|
|
|
- }
|
|
|
- if (dto.getAnswer().length() < 32767) {
|
|
|
- row.createCell(11).setCellValue(dto.getAnswer());
|
|
|
+ File file = new File(quesExcelPathNew);
|
|
|
+
|
|
|
+ try (Workbook workBook = new XSSFWorkbook(ddExcelFile);
|
|
|
+ OutputStream out = new FileOutputStream(file);) {
|
|
|
+
|
|
|
+ //获取第一个工作页
|
|
|
+ Sheet sheet = workBook.getSheetAt(0);
|
|
|
+
|
|
|
+ //标题
|
|
|
+ Row titleRow = sheet.createRow(0);
|
|
|
+ titleRow.createCell(0).setCellValue("课程代码");
|
|
|
+ titleRow.createCell(1).setCellValue("课程名称");
|
|
|
+ titleRow.createCell(2).setCellValue("试卷名称");
|
|
|
+ titleRow.createCell(3).setCellValue("原始试卷ID");
|
|
|
+ titleRow.createCell(4).setCellValue("大题号");
|
|
|
+ titleRow.createCell(5).setCellValue("小题号");
|
|
|
+ titleRow.createCell(6).setCellValue("标准分");
|
|
|
+ titleRow.createCell(7).setCellValue("大题名称");
|
|
|
+ titleRow.createCell(8).setCellValue("题干");
|
|
|
+ titleRow.createCell(9).setCellValue("题干(含标签)");
|
|
|
+ titleRow.createCell(10).setCellValue("标答");
|
|
|
+ titleRow.createCell(11).setCellValue("标答(含标签)");
|
|
|
+
|
|
|
+ //向Excel中写入数据,从第2行开始
|
|
|
+ for (int i = 0; i < subjectQuestions.size(); i++) {
|
|
|
+ //创建一行:从第1行开始,跳过表头
|
|
|
+ Row row = sheet.createRow(i + 1);
|
|
|
+ SubQuestionDto dto = subjectQuestions.get(i);
|
|
|
+ //每列赋值
|
|
|
+ row.createCell(0).setCellValue(dto.getCourseCode());
|
|
|
+ row.createCell(1).setCellValue(dto.getCourseName());
|
|
|
+ row.createCell(2).setCellValue(dto.getPaperName());
|
|
|
+ row.createCell(3).setCellValue(dto.getPaperId());
|
|
|
+ row.createCell(4).setCellValue(dto.getdNumber());
|
|
|
+ row.createCell(5).setCellValue(dto.getNumber());
|
|
|
+ row.createCell(6).setCellValue(dto.getScore());
|
|
|
+ row.createCell(7).setCellValue(dto.getDetailName());
|
|
|
+ row.createCell(8).setCellValue(dto.getClearBody());
|
|
|
+ row.createCell(9).setCellValue(dto.getBody());
|
|
|
+ if (dto.getClearAnswer().length() < 32767) {
|
|
|
+ row.createCell(10).setCellValue(dto.getClearAnswer());
|
|
|
+ }
|
|
|
+ if (dto.getAnswer().length() < 32767) {
|
|
|
+ row.createCell(11).setCellValue(dto.getAnswer());
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ workBook.write(out);
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ } catch (InvalidFormatException e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
}
|
|
|
- File file = new File(quesExcelPathNew);
|
|
|
- OutputStream out = new FileOutputStream(file);
|
|
|
- workBook.write(out);
|
|
|
- out.close();
|
|
|
+
|
|
|
log.debug("结束...");
|
|
|
}
|
|
|
|