|
@@ -0,0 +1,34 @@
|
|
|
+package com.yaoxiang.diagnosis.service;
|
|
|
+
|
|
|
+import com.yaoxiang.diagnosis.word.WordUtil;
|
|
|
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
|
|
+import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
|
|
+import org.junit.Test;
|
|
|
+import org.springframework.util.FileCopyUtils;
|
|
|
+
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+public class WordTest {
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void test() throws Exception{
|
|
|
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
+ File file = new File("doc/table.docx");
|
|
|
+ InputStream is = new FileInputStream(file);
|
|
|
+ FileCopyUtils.copy(is, baos);
|
|
|
+ is.close();
|
|
|
+ byte[] data = baos.toByteArray();
|
|
|
+ XWPFDocument document = WordUtil.open(data);
|
|
|
+ List<XWPFParagraph> paragraphs = document.getParagraphs();
|
|
|
+ for (XWPFParagraph paragraph:paragraphs){
|
|
|
+ System.out.println(paragraph.getCTP().xmlText());
|
|
|
+ System.out.println(paragraph.getCTP().isImmutable());
|
|
|
+ System.out.println(paragraph.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|