deason 6 anos atrás
pai
commit
dc85f9e53b

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

@@ -36,19 +36,19 @@ public interface Constants {
     String PRT_CODE_403 = "PRT-000403";
 
     /* 导出文件默认名称 */
-    String PAPER_DOC_NAME = "试卷.doc";
-    String ANSWER_DOC_NAME = "答案.doc";
+    String PAPER_DOC_NAME = "试卷.docx";
+    String ANSWER_DOC_NAME = "答案.docx";
     String PAPER_PDF_NAME = "试卷.pdf";
     String ANSWER_PDF_NAME = "答案.pdf";
     String STRUCT_ZIP_NAME = "试卷结构.zip";
-    String OBJECTIVE_EXCEL_NAME = "客观题.xls";
-    String SUBJECTIVE_EXCEL_NAME = "主观题.xls";
+    String OBJECTIVE_EXCEL_NAME = "客观题.xlsx";
+    String SUBJECTIVE_EXCEL_NAME = "主观题.xlsx";
     String PAPER_DIR = "paper";
     String ANSWER_DIR = "answer";
 
     String SUFFIX_ZIP = ".zip";
-    String SUFFIX_WORD = ".doc";
-    String SUFFIX_EXCEL = ".xls";
+    String SUFFIX_WORD = ".docx";
+    String SUFFIX_EXCEL = ".xlsx";
 
     static String rootFileDir() {
         return Constants.class.getClassLoader().getResource("").getPath() + "/files";

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

@@ -9,7 +9,9 @@ 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 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;
@@ -27,16 +29,22 @@ import java.util.List;
 public class ExcelUtils {
     private static Logger log = LoggerFactory.getLogger(ExcelUtils.class);
 
+    public static <T> void toExcelFile(Class<T> clazz, List<T> list, File excelFile) {
+        toExcelFile(clazz, list, excelFile, null);
+    }
+
     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.");
             return;
         }
 
-        if (StringUtils.isBlank(title)) {
-            title = "";
+        ExportParams params = new ExportParams();
+        params.setType(ExcelType.XSSF);
+        //params.setColor(IndexedColors.AQUA.getIndex());
+        if (StringUtils.isNotBlank(title)) {
+            params.setTitle(title);
         }
-        ExportParams params = new ExportParams(title, title);
 
         try (FileOutputStream fos = new FileOutputStream(excelFile);
              Workbook workbook = ExcelExportUtil.exportExcel(params, clazz, list);) {

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

@@ -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), "客观题数据");
 
             final String subjectiveFile = targetDir + "/" + SUBJECTIVE_EXCEL_NAME;
-            ExcelUtils.toExcelFile(SubjectiveQuestionStructure.class, allSubjectives, new File(subjectiveFile), "");
+            ExcelUtils.toExcelFile(SubjectiveQuestionStructure.class, allSubjectives, new File(subjectiveFile), "主观题数据");
         }
 
         //压缩打包所有文件