deason il y a 6 ans
Parent
commit
eb76f238ef

+ 2 - 0
examcloud-core-print-common/src/main/java/cn/com/qmth/examcloud/core/print/common/Constants.java

@@ -43,6 +43,8 @@ public interface Constants {
     String STRUCT_ZIP_NAME = "试卷结构.zip";
     String OBJECTIVE_EXCEL_NAME = "客观题.xlsx";
     String SUBJECTIVE_EXCEL_NAME = "主观题.xlsx";
+    String OBJECTIVE_TITLE = "客观题数据";
+    String SUBJECTIVE_TITLE = "主观题数据";
     String PAPER_DIR = "paper";
     String ANSWER_DIR = "answer";
 

+ 5 - 3
examcloud-core-print-common/src/main/java/cn/com/qmth/examcloud/core/print/common/utils/ExcelUtils.java

@@ -10,8 +10,8 @@ package cn.com.qmth.examcloud.core.print.common.utils;
 import cn.afterturn.easypoi.excel.ExcelExportUtil;
 import cn.afterturn.easypoi.excel.entity.ExportParams;
 import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
+import cn.afterturn.easypoi.excel.export.styler.ExcelExportStylerBorderImpl;
 import org.apache.commons.lang3.StringUtils;
-import org.apache.poi.ss.usermodel.IndexedColors;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -35,15 +35,17 @@ public class ExcelUtils {
 
     public static <T> void toExcelFile(Class<T> clazz, List<T> list, File excelFile, String title) {
         if (excelFile == null) {
-            log.warn("excelFile must be not null.");
+            log.warn("[Param] excelFile is null.");
             return;
         }
 
         ExportParams params = new ExportParams();
         params.setType(ExcelType.XSSF);
-        //params.setColor(IndexedColors.AQUA.getIndex());
+        params.setStyle(ExcelExportStylerBorderImpl.class);
+
         if (StringUtils.isNotBlank(title)) {
             params.setTitle(title);
+            params.setSheetName(title);
         }
 
         try (FileOutputStream fos = new FileOutputStream(excelFile);

+ 3 - 3
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/impl/CoursePaperServiceImpl.java

@@ -314,7 +314,7 @@ public class CoursePaperServiceImpl implements CoursePaperService {
         return packageFiles(exportFiles, allObjectives, allSubjectives, req.getNeedStruct());
     }
 
-    private File packageFiles(List<ExportFileInfo> exportFiles, List<ObjectiveQuestionStructure> allObjectives, List<SubjectiveQuestionStructure> allSubjectives, Boolean needStruct) {
+    private File packageFiles(List<ExportFileInfo> exportFiles, List<ObjectiveQuestionStructure> allObjectives, List<SubjectiveQuestionStructure> allSubjectives, boolean needStruct) {
         //文件存放目录
         final String rootDir = Constants.rootFileDir();
         final String targetDir = rootDir + "/" + FileUtils.randomUUID();
@@ -334,10 +334,10 @@ public class CoursePaperServiceImpl implements CoursePaperService {
         //生成试卷结构文件
         if (needStruct) {
             final String objectiveFile = targetDir + "/" + OBJECTIVE_EXCEL_NAME;
-            ExcelUtils.toExcelFile(ObjectiveQuestionStructure.class, allObjectives, new File(objectiveFile), "客观题数据");
+            ExcelUtils.toExcelFile(ObjectiveQuestionStructure.class, allObjectives, new File(objectiveFile), OBJECTIVE_TITLE);
 
             final String subjectiveFile = targetDir + "/" + SUBJECTIVE_EXCEL_NAME;
-            ExcelUtils.toExcelFile(SubjectiveQuestionStructure.class, allSubjectives, new File(subjectiveFile), "主观题数据");
+            ExcelUtils.toExcelFile(SubjectiveQuestionStructure.class, allSubjectives, new File(subjectiveFile), SUBJECTIVE_TITLE);
         }
 
         //压缩打包所有文件