I have a word document which may have n number of tables. The table is identified by the table name which is written in the 1st cell as heading. Now i have to find the table with table name and write in one of the cell of that table. I tried using apache-poi for the same but unable to figure out how to use it for my purpose. Please refer to the attached screen shot, if i am not able to explain how the document looks like.
Thanks
String fileName = "E:\\a1.doc";
if (args.length > 0) {
fileName = args[0];
}
InputStream fis = new FileInputStream(fileName);
POIFSFileSystem fs = new POIFSFileSystem(fis);
HWPFDocument doc = new HWPFDocument(fs);
Range range = doc.getRange();
for (int i=0; i<range.numParagraphs(); i++){
Paragraph tablePar = range.getParagraph(i);
if (tablePar.isInTable()) {
Table table = range.getTable(tablePar);
for (int rowIdx=0; rowIdx<table.numRows(); rowIdx++) {
for (int colIdx=0; colIdx<row.numCells(); colIdx++) {
TableCell cell = row.getCell(colIdx);
System.out.println("column="+cell.getParagraph(0).text());
}
}
}
}
this is what i have tried, but this reads only the 1st table.