|
@@ -18,6 +18,7 @@ import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
import org.apache.commons.lang3.ArrayUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.docx4j.openpackaging.exceptions.Docx4JException;
|
|
|
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
|
|
|
import org.docx4j.wml.P;
|
|
|
import org.slf4j.Logger;
|
|
@@ -576,9 +577,6 @@ public class ImportPaperService {
|
|
|
public String processQuesOption(List<Object> pList, int index, int subQuesNum, Question question,
|
|
|
ImportPaperCheck importPaperCheck, WordprocessingMLPackage wordMLPackage) throws Exception {
|
|
|
|
|
|
- // 定义试题选项wordml和html
|
|
|
- // String quesOptionWordMl = "";
|
|
|
- // String quesOptionHtml = "";
|
|
|
// 定义选项集合
|
|
|
List<QuesOption> quesOptions = new ArrayList<QuesOption>();
|
|
|
// 定义选项数量
|
|
@@ -588,7 +586,6 @@ public class ImportPaperService {
|
|
|
int i = 0;
|
|
|
int number = 0;
|
|
|
for (i = index; i < pList.size(); i++) {
|
|
|
- number++;
|
|
|
P pOption = (P) pList.get(i);
|
|
|
String tmpText = DocxProcessUtil.getPText(pOption);
|
|
|
if (StringUtils.isEmpty(tmpText) && DocxProcessUtil.isText(pOption)) {
|
|
@@ -602,9 +599,14 @@ public class ImportPaperService {
|
|
|
} else if (tmpText.matches("^[a-zA-Z]\\.[\\s\\S]*")) {
|
|
|
// 检测到选项开始段落
|
|
|
// 创建试题选项
|
|
|
+ number++;
|
|
|
current = new QuesOption();
|
|
|
- String optionNumber = String.valueOf(number);
|
|
|
- current.setNumber(optionNumber);
|
|
|
+ int optionNumber = DocxProcessUtil.getOptionNum(tmpText);
|
|
|
+ if(optionNumber != number){
|
|
|
+ importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, subQuesNum)+ImportPaperMsg.errMsg_13);
|
|
|
+ throw new PaperException(importPaperCheck.errorInfo);
|
|
|
+ }
|
|
|
+ current.setNumber(String.valueOf(optionNumber));
|
|
|
current.setOptionBody("");
|
|
|
current.setOptionBodyWord("");
|
|
|
quesOptions.add(current);
|
|
@@ -1094,9 +1096,17 @@ public class ImportPaperService {
|
|
|
String word = replaceContent.replace("[", "").replace("]", "");
|
|
|
return pText.replaceAll("\\["+word+"\\]","").replaceAll("[:|:]", "").trim();
|
|
|
}
|
|
|
+
|
|
|
public static void main(String[] args){
|
|
|
- String answer = "a";
|
|
|
- String pattern = "[A-Z]|[a-z]";
|
|
|
- System.out.println(Pattern.matches(pattern,answer));
|
|
|
+ try {
|
|
|
+ File file = new File("/Users/songyue/Downloads/行政组织学A卷.docx");
|
|
|
+ File outFile = new File("/Users/songyue/Downloads/行政组织学A1卷.docx");
|
|
|
+ WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(file);
|
|
|
+ DocxProcessUtil.initPkgImage(wordMLPackage);
|
|
|
+ wordMLPackage.save(outFile);
|
|
|
+ } catch (Docx4JException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }finally {
|
|
|
+ }
|
|
|
}
|
|
|
}
|