How can I get footnotes and paragraphs from Apache POI?

倾然丶 夕夏残阳落幕 提交于 2019-12-22 09:48:32

问题


I have code to get paragraphs from a .doc file in Apache POI, but I'd like to get footnotes also. Also, is this the only way to get paragraphs?

Code so far:

    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();
    }

Any ideas?


回答1:


You could try this...

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


来源:https://stackoverflow.com/questions/36392563/how-can-i-get-footnotes-and-paragraphs-from-apache-poi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!