获取到项目中的word文档并打印出来

String params="/doc/company_agreement.docx";
Resource srcFile = new ClassPathResource(params);
XWPFDocument document = new XWPFDocument(srcFile.getInputStream());//获取文档
Iterator<XWPFParagraph> itParagraph = document.getParagraphsIterator();
while (itParagraph.hasNext()) {
    XWPFParagraph paragraph = itParagraph.next();
    List<XWPFRun> runs = paragraph.getRuns();
    for (int i = 0; i < runs.size(); i++) {
        XWPFRun run = runs.get(i);
        String text = run.getText(0);
        System.out.println(text);
    }
}
展开阅读全文

没有更多推荐了,返回首页