|
@@ -1,9 +1,18 @@
|
|
|
package com.yaoxiang.diagnosis.service;
|
|
|
|
|
|
|
|
|
+import com.microsoft.schemas.office.office.OLEObjectDocument;
|
|
|
import com.yaoxiang.diagnosis.entity.Paper;
|
|
|
import com.yaoxiang.diagnosis.entity.PaperTemplate;
|
|
|
import com.yaoxiang.diagnosis.util.CommonUtil;
|
|
|
+import com.yaoxiang.diagnosis.util.ObjectUtil;
|
|
|
+import com.yaoxiang.diagnosis.word.WordUtil;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
+import org.apache.poi.xwpf.usermodel.VerticalAlign;
|
|
|
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
|
|
+import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
|
|
+import org.apache.poi.xwpf.usermodel.XWPFRun;
|
|
|
import org.junit.Test;
|
|
|
import org.springframework.core.io.ByteArrayResource;
|
|
|
import org.springframework.http.HttpEntity;
|
|
@@ -14,7 +23,8 @@ import org.springframework.util.LinkedMultiValueMap;
|
|
|
import org.springframework.util.MultiValueMap;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
-import java.io.File;
|
|
|
+import java.io.*;
|
|
|
+import java.util.*;
|
|
|
|
|
|
public class UploadTest {
|
|
|
|
|
@@ -67,4 +77,65 @@ public class UploadTest {
|
|
|
System.out.println(paper.getCode());
|
|
|
System.out.println(paper.getGrade());
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void test3() throws Exception {
|
|
|
+ XWPFDocument document = WordUtil.open("doc/sub.docx");
|
|
|
+ List<XWPFParagraph> paragraphs = document.getParagraphs();
|
|
|
+ for (XWPFParagraph paragraph : paragraphs) {
|
|
|
+ List<XWPFRun> runs = paragraph.getRuns();
|
|
|
+
|
|
|
+ List<XWPFRun> runs1 = deepCopy(runs);
|
|
|
+
|
|
|
+
|
|
|
+ System.out.println("before parse " + paragraph.getText());
|
|
|
+ System.out.println("runs size " + runs.size());
|
|
|
+
|
|
|
+ Iterator<XWPFRun> it = runs1.iterator();
|
|
|
+ int i = 0;
|
|
|
+ Map<Integer, String> insert = new HashMap<>();
|
|
|
+ while (it.hasNext()) {
|
|
|
+ XWPFRun run = it.next();
|
|
|
+ switch (run.getSubscript()) {
|
|
|
+ case BASELINE:
|
|
|
+ break;
|
|
|
+ case SUBSCRIPT:
|
|
|
+
|
|
|
+ paragraph.insertNewRun(i).setText("<sub>");
|
|
|
+ paragraph.insertNewRun(++i).setText("</sub>");
|
|
|
+
|
|
|
+ break;
|
|
|
+ case SUPERSCRIPT:
|
|
|
+ paragraph.insertNewRun(i).setText("<sup>");
|
|
|
+ paragraph.insertNewRun(++i).setText("</sup>");
|
|
|
+
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ System.out.println("after parse " + paragraph.getText());
|
|
|
+ System.out.println("runs size " + runs.size());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static <T> List<T> deepCopy(List<T> src) throws IOException, ClassNotFoundException {
|
|
|
+ ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
|
|
|
+ ObjectOutputStream out = new ObjectOutputStream(byteOut);
|
|
|
+ out.writeObject(src);
|
|
|
+
|
|
|
+ ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
|
|
|
+ ObjectInputStream in = new ObjectInputStream(byteIn);
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ List<T> dest = (List<T>) in.readObject();
|
|
|
+ return dest;
|
|
|
+ }
|
|
|
}
|