Example usage for org.apache.poi.xwpf.usermodel XWPFDocument getParagraphs

List of usage examples for org.apache.poi.xwpf.usermodel XWPFDocument getParagraphs

Introduction

In this page you can find the example usage for org.apache.poi.xwpf.usermodel XWPFDocument getParagraphs.

Prototype

@Override
public List<XWPFParagraph> getParagraphs() 

Source Link

Usage

From source file:textextractor.WordManager.java

public ArrayList extractDocx(FileInputStream fis) throws IOException {
    listDocx = new ArrayList();
    XWPFDocument docx = new XWPFDocument(fis);
    List<XWPFParagraph> pragraphList = docx.getParagraphs();
    pragraphList.stream().forEach((pragraph) -> {
        if (pragraph.getStyle() != null) {
            System.out.println(pragraph.getStyle());
        }//from www .j ava  2s .co  m
        System.out.println(pragraph.getText());
        String[] ary = pragraph.getText().split(" ");
        listDocx.addAll(Arrays.asList(ary));
    });
    return listDocx;
}

From source file:util.DocumentFunction.java

public static String readDocxFile(String fileName) {
    StringBuilder text = new StringBuilder();
    try {/*from   w w  w .j a  v  a  2  s  .  com*/
        File file = new File(fileName);
        FileInputStream fis = new FileInputStream(file.getAbsolutePath());

        XWPFDocument document = new XWPFDocument(fis);

        List<XWPFParagraph> paragraphs = document.getParagraphs();

        //System.out.println("Total no of paragraph "+paragraphs.size());
        for (XWPFParagraph para : paragraphs) {
            text.append(para.getText() + "\n");
        }
        fis.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return text.toString();
}