Hi wrotten the following program in order to read paragraph and tables 
in a word document:

package prezziarioreader;
import org.apache.poi.
hwpf.HWPFDocument;
import org.apache.poi.hwpf.usermodel.Range;
import 
org.apache.poi.hwpf.usermodel.Paragraph;
import org.apache.poi.hwpf.
usermodel.Table;
import org.apache.poi.hwpf.model.ListTables;
import 
java.io.*;


public class Main {


    public static void main(String[] 
args) {
        // TODO code application logic here
        try{

            HWPFDocument doc = new HWPFDocument(new FileInputStream("d:
\\prova.doc"));
            Range r = doc.getRange ();

            int 
sectionLevel = 0;
            int lenParagraph = r.numParagraphs ();

            boolean inCode = false;
            String text;

            Paragraph p;
            for (int x = 0; x < lenParagraph; 
x++){
                p = r.getParagraph (x);
                if (p.
isInTable()){                   
                    Table tab = r.
getTable(p);
                    System.out.println("Paragraph " + x + 
":"+"Table with " +tab.numRows() + "rows.");
                }

                else{
                    text = p.text ();

                    System.out.println("Paragraph " + x + ":" + text);

                }
            }
        }
        catch (IOException e)
{
            System.err.println(e);
        }
    }

}

I got a 
problem during the execution; It read well the simple paragraphs but 
when there's a table i got the following error message:

Exception in 
thread "main" java.lang.IllegalArgumentException: This paragraph is not 
the first one in the table
        at org.apache.poi.hwpf.usermodel.
Range.getTable(Range.java:873)

What's worng?


Promozione Primavera ! Sulle foto 13x17 e 13x19 sconti fino al 57%. Tutto a 
soli 0,11 €. Solo su Tiscali Photo

http://photo.tiscali.it/offerte/promo-primavera.shtml

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to