No single method exists that allows you to read data from tables in the way you are seeking; you will have to write that yourself. I do not have the code on hand now but the basic approach will be this;
Open the Word document. >From the document retrieve the Range object that represents the contents of the document by calling the getRange() method. On that Range object, call the numParagraphs() method to discover how many paragraphs there are in the document. Using this. number, yoiu can create a conditioned loop within which you can call the getParagraph(int) method of the top level Range object to recover the Paragraph objects one at a time. Check if the Paragarph object represents text that is contained within a table by calling the Paragraphs isInTable() method. If this method returns true then you can get at the actual table holding the data by calling the getTable() method of the high level Range and pass the Paragraph object to it. Be aware though that when I did this originally, getTable() could only be called on the first paragraph in the table, it threw an exception if I tried to call it for the second, third, etc paragraph. Now that you have a Table object it is a simple task to iterate through the rows - numRows() will tell you how many there are and getRow(int) will retrieve a row for you. Once you have the row object, get each cell it contains - numCells() and getCell(int). With an instance of the TableCell class in hand, you have a choice to make, do you simply want the text - in which case you can call the text() method of the cell, or do you want more information - font etc. Of course, if all you want is text from the table and you do not care where abouts in the table it came from, simply get the paragraph and check if it is in a table. If it is, store the data if not discard it. Much simpler but maybe not wnat you want. Try that for starters. Writing is a similar process but in reverse if I remember correctly. If I have the time I will try to put some code together but I am currently away from my office desk and do not have access to the api so cannot promise when I will be able to do this. Yours Mark B -- View this message in context: http://apache-poi.1045710.n5.nabble.com/Create-and-read-table-cotents-in-doc-file-tp4293563p4295291.html Sent from the POI - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
