poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From MSB <markbrd...@tiscali.co.uk>
Subject Re: reading Tables
Date Wed, 08 Apr 2009 06:55:11 GMT

I am by no means an expert at using HWPF but I think that there may be a way
to accomplish what you require; unfortunately, I will not have the time to
put together any code until this evening as I am working off site today.
Sorry to say that I cannot guarantee this will work but you could try
something like this;

// Open the Word document
HWPFDocument do = new HWPFDocument(new
java.io.FileInputStream("C:\\temp\\test.doc"));
// Get the Range object that describes the document
Range range = doc.getRange();
// Get at the number of Paragraphs
int numParas = range.numParagraphs();
Paragraph para = null;
Table table = null;
// Step through the Paragraphs
for(int i = 0; i < numParas; i++) {
    // Get a paragraph and test to see if it in a table
    para = range.getParagraph(i);
    if(para.isInTable()) {
        // If it is in a table, get that table. This will only work
        // I believe if the Paragrpah is the first one in the
        // table but I could be wrong.
        table = range.getTable(para);
    }
}

that should get you to the table, but there are still LOTS of problems with
this code; other paragraphs could be in the same table so we need to find a
way to condition the code so that we do not cause errors by trying to
process those, still you need to decide how to process the contents of the
table once we have it. Tonight, I will have the time to dig around further
and will try to put together something a little more substabtial. In the
meantime, feel free to play with the code yourself and let me know if it
works firstly and whether you have improved it please.



codaditasso@tiscali.it wrote:
> 
> Hi
> Anyone could post me the minimal code to get the list of all tables 
> in a word document. In particular i want to have a class from i could 
> extract the Object "Table" from each table in the document.
> Greetings
> 
> Enrico 
> 
> 
> Con Tutto Incluso chiami e navighi senza limiti e hai 4 mesi GRATIS.
> 
> L'attivazione del servizio è gratis e non paghi più Telecom! 
> 
> L'offerta è valida solo se attivi entro il 07/04/09
> http://abbonati.tiscali.it/promo/tuttoincluso/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/reading-Tables-tp22911444p22944362.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Mime
View raw message