如何从Apache POI获取脚注和段落?

时间:2016-04-03 23:33:16

标签: java apache-poi

我有代码从Apache POI中的.doc文件中获取段落,但我也想获得脚注。另外,这是获取段落的唯一方法吗?

到目前为止

代码:

    InputStream stream = ...
    HWPFDocument document = new HWPFDocument(stream);
    Range range = document.getRange();

    StyleSheet stylesheet = document.getStyleSheet();

    for (int i = 0; i < range.numParagraphs(); i++) {
        Paragraph paragraph = range.getParagraph(i);

        String text = paragraph.text();
    }

有什么想法吗?

1 个答案:

答案 0 :(得分:3)

你可以试试这个......

WordExtractor extractor = new WordExtractor(document);
paragraphs.addAll(Arrays.asList(extractor.getParagraphText()) ); 
footnotes.addAll(Arrays.asList(extractor.getFootnoteText()) );
extractor.close();