소스 검색

修改word导入导出问题

宋悦 8 년 전
부모
커밋
4e825b1d2d

+ 7 - 3
cqb-comm-utils/src/main/java/com/qmth/cqb/utils/word/DocxProcessUtil.java

@@ -832,10 +832,14 @@ public final class DocxProcessUtil {
      */
     public static String html2Docx(WordprocessingMLPackage wordMLPackage,String html)throws Exception {
         initTmpPackage(wordMLPackage);
+        RFonts rfonts = Context.getWmlObjectFactory().createRFonts();
+        rfonts.setAscii("eastAsia");
+        XHTMLImporterImpl.addFontMapping("eastAsia", rfonts);
         XHTMLImporterImpl XHTMLImporter = new XHTMLImporterImpl(wordMLPackage);
+        XHTMLImporter.setHyperlinkStyle("Hyperlink");
         String wordMl = "";
         wordMLPackage.getMainDocumentPart().getContent().addAll(
-                    XHTMLImporter.convert( repairHtmlStr(html), null) );
+                    XHTMLImporter.convert( repairHtmlStr(html), TEMP_FILE_IMP) );
         // 获取word文档中所有段落
         List<Object> pList = getAllElementFromObject(wordMLPackage.getMainDocumentPart(), P.class);
         for(Object p:pList){
@@ -846,7 +850,7 @@ public final class DocxProcessUtil {
         return wordMl;
     }
 
-    public static String repairHtmlStr(String htmlStr){
+    public static String repairHtmlStr(String htmlStr)throws Exception{
         htmlStr = htmlStr.trim();
         if(htmlStr.toLowerCase().contains("<!doctype html ")){
             int index1 = htmlStr.toLowerCase().indexOf("<!doctype html ");
@@ -888,7 +892,7 @@ public final class DocxProcessUtil {
                 imgIndex = indexOfRegex(htmlStr,"<((img)|(IMG)) ",flag);
             }
         }
-        return htmlStr;
+        return new String(htmlStr.getBytes("UTF-8"));
     }
 
     /**

+ 3 - 1
cqb-paper/src/main/java/com/qmth/cqb/paper/service/ExportPaperService.java

@@ -220,12 +220,14 @@ public class ExportPaperService {
         }
         if(StringUtils.isEmpty(optionOrder)){
             int j = 0;
+            String answer = "";
             for(QuesOption quesOption : quesOptions){
                 if(quesOption.getIsCorrect() == 1){
-                    question.setQuesAnswerWord(getObjectAnswer(question.getQuesAnswerWord(),CommonUtils.getOptionNum(j)));
+                    answer += CommonUtils.getOptionNum(j);
                 }
                 j++;
             }
+            question.setQuesAnswerWord(getObjectAnswer(question.getQuesAnswerWord(),answer));
         }else{
             String [] order = optionOrder.split(",");
             for(int i = 0;i < order.length;i++){

+ 3 - 1
cqb-paper/src/main/java/com/qmth/cqb/paper/service/ExtractConfigServiceImpl.java

@@ -452,12 +452,14 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
 		}
 		if(StringUtils.isEmpty(optionOrder)){
 			int j = 0;
+			String answer = "";
 			for(QuesOption quesOption : quesOptions){
 				if(quesOption.getIsCorrect() == 1){
-					question.setQuesAnswer(CommonUtils.getOptionNum(j));
+					answer += CommonUtils.getOptionNum(j);
 				}
 				j++;
 			}
+			question.setQuesAnswer(answer);
 		}else{
 			String [] order = optionOrder.split(",");
 			for(int i = 0;i < order.length;i++){

+ 3 - 1
cqb-question-resource/src/main/java/com/qmth/cqb/question/service/QuesService.java

@@ -287,7 +287,9 @@ public class QuesService {
         if(!StringUtils.isEmpty(quesBody)){
             question.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, quesBody));
         }
-        if(!StringUtils.isEmpty(quesAnswer)){
+        if(!StringUtils.isEmpty(quesAnswer)
+                && question.getQuestionType() == QuesStructType.FILL_BLANK_QUESTION
+                && question.getQuestionType() == QuesStructType.TEXT_ANSWER_QUESTION){
             question.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage, quesAnswer));
         }
         List<QuesOption> quesOptions = question.getQuesOptions();