How to read content from ms word files using Jakarta POI

后端 未结 4 1762
忘掉有多难
忘掉有多难 2021-01-25 15:58

I\'ve included jakarta-poi-1.5.1-final-20020615.jar file to read content from ms word.

I am unable to do this ...can anyone help me?

4条回答
  •  春和景丽
    2021-01-25 16:10

    Use this code with apache-poi

    XWPFDocument doc = new XWPFDocument(new FileInputStream(fileName));
        List table = doc.getTables();
        for (XWPFTable xwpfTable : table) {
            List row = xwpfTable.getRows();
            for (XWPFTableRow xwpfTableRow : row) {
                List cell = xwpfTableRow.getTableCells();
                for (XWPFTableCell xwpfTableCell : cell) {
                    if (xwpfTableCell != null) {
                        System.out.println(xwpfTableCell.getText());
                        String s = xwpfTableCell.getText();
                        for (XWPFParagraph p : xwpfTableCell.getParagraphs()) {
                            for (XWPFRun run : p.getRuns()) {
                                for (XWPFPicture pic : run.getEmbeddedPictures()) {
                                    byte[] pictureData = pic.getPictureData().getData();
                                    System.out.println("picture : " + pictureData);
                                }
                            }
                        }
                    }
                }
            }
        }
    

提交回复
热议问题