Эх сурвалжийг харах

后端:完成空行过滤的功能

weiwenhai 7 жил өмнө
parent
commit
4f550ca76a

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

@@ -967,11 +967,35 @@ public final class DocxProcessUtil {
         }
         return -1;
     }
-
+    
+    /**
+     * 检测P标签中是否有值
+     * @return
+     */
+    public static boolean isTextFromP(String strHtml){
+    	String value = "";
+    	String regex = "<p>(.*)</p>";
+    	Pattern pattern = Pattern.compile(regex);
+    	Matcher matcher = pattern.matcher(strHtml);
+    	while(matcher.find()){
+    		value = matcher.group(1);
+	    }
+    	if(StringUtils.isBlank(value)){
+    		return true;
+    	}
+    	return false;
+    }
+    
     public static void main(String[] args) throws Exception {
 //        System.out.println(formatPWordMl("<p>A</p>"));
 //        System.out.println(getOptionNum("A.123123123"));
-    	System.out.println(getTextInHtml("<p>#include <stdio.h></p>"));
-        
+//    	System.out.println(getTextInHtml("<p>#include <stdio.h></p>"));
+    	StringBuilder str = new StringBuilder("");
+    	str.append("<p>11</p>");
+    	str.append("<p></p>");
+    	String html = str.toString();
+    	int index = html.lastIndexOf("<p>");
+    	String htm = html.substring(0,index);
+    	System.out.println(htm);
     }
 }

+ 4 - 2
cqb-paper/src/main/java/com/qmth/cqb/paper/service/ImportPaperService.java

@@ -752,8 +752,10 @@ public class ImportPaperService {
                 	answerWordML.append(DocxProcessUtil.formatPWordMl(tmpWordMl));
                     answerHTML.append(answerText);
                 }else{
-                    answerWordML.append(DocxProcessUtil.formatPWordMl(tmpWordMl));
-                    answerHTML.append(DocxProcessUtil.docx2Html(tmpWordMl, wordMLPackage));
+                    if(!DocxProcessUtil.isTextFromP(DocxProcessUtil.docx2Html(tmpWordMl, wordMLPackage))){
+                    	answerWordML.append(DocxProcessUtil.formatPWordMl(tmpWordMl));
+                    	answerHTML.append(DocxProcessUtil.docx2Html(tmpWordMl, wordMLPackage));
+                    }
                 }
                 answerStart = true;
             } else if (tmpText.startsWith(ImportPaperMsg.subQuesScore_word)) {