Quantcast
Channel: Java Programming Forum - Learn Java Programming - Apache POI
Viewing all articles
Browse latest Browse all 120

Error while reading table into a doc file

$
0
0
Hi all, i'm new here and with Apache POI.

I would like to read a .doc file line by line and create a .pdf with text, table and image retrieved by the doc file. Now I managed to do it but not in order: I have written some code that extract text, table data, and image but I can't determine where those object are in the document.

All this because of if I try to run this code, who allow me to read the document paragraph by paragraph, I obtain a error.

that code follow:

Code:

        InputStream fis = new FileInputStream(input); 
        POIFSFileSystem fs = new POIFSFileSystem(fis); 
        HWPFDocument doc = new HWPFDocument(fs);
        Range range = doc.getRange();

        for (int i=0;i<range.numParagraphs();i++) {
                org.apache.poi.hwpf.usermodel.Paragraph par = range.getParagraph(i);
                if(!par.isInTable()) {
                        .......
                } else if (par.isInTable()) {
                        Table table = range.getTable(par);/**/
                        for (int rowId=0;rowId<table.numRows();rowId++) {
                                TableRow tRow = table.getRow(rowId);
                                for (int cellId=0;cellId<tRow.numCells();cellId++) {
                                        TableCell tCell = tRow.getCell(cellId);
                                        tCell.text();
                                }
                        }
                }
        }

The exception is:
Code:

........... The paragraph is not the first one in a table.
How can i Solve this??

Thanks a lot and sorry for my english.

Viewing all articles
Browse latest Browse all 120

Trending Articles