Пример #1
0
 /**
  * 解析所有的文本
  *
  * @author Zerrion
  * @date 2013-11-17
  * @param paragraphs
  * @param map
  */
 private void parseAllParagraphic(List<XWPFParagraph> paragraphs, Map<String, Object> map)
     throws Exception {
   XWPFParagraph paragraph;
   for (int i = 0; i < paragraphs.size(); i++) {
     paragraph = paragraphs.get(i);
     if (paragraph.getText().indexOf("{{") != -1) {
       parseThisParagraph(paragraph, map);
     }
   }
 }
Пример #2
0
 /** @param args the command line arguments */
 public void ReadParagraph(String path, String filename) {
   try {
     FileInputStream fis = new FileInputStream(path + filename + ".docx");
     XWPFDocument xdoc = new XWPFDocument(OPCPackage.open(fis));
     List<XWPFParagraph> paragraphList = xdoc.getParagraphs();
     for (XWPFParagraph paragraph : paragraphList) {
       System.out.println(paragraph.getText());
     }
   } catch (Exception ex) {
     ex.printStackTrace();
   }
 }
Пример #3
0
  public static String readFileDocx(String filePath) {

    StringBuilder text = new StringBuilder();
    try {

      FileInputStream fileInputStream = new FileInputStream(new File(filePath));
      XWPFDocument doc = new XWPFDocument(fileInputStream);

      XWPFParagraph[] paragraphs = doc.getParagraphs();
      for (XWPFParagraph paragraph : paragraphs) {
        text.append(" ");
        text.append(paragraph.getText());
      }

    } catch (Exception e) {
      e.printStackTrace();
    }

    return text.toString();
  }