Hi, I am using Apache POI 3.9 to extract table contents from a .docx file.This doc contains multiple tables under different sections.I could extract all the table contents irrespective of the sections , but i want to extract table content under particular sections only.Can anyone help ?
*.docx outline:* */Section 1: ABC/* Table 1: Table 2: */Section 2 :CDE/* Table 3: Table 4: * Table Extraction Code:* XWPFDocument documentContent = new XWPFDocument(inputStream); Iterator<IBodyElement> bodyElementIterator = documentContent.getBodyElementsIterator(); while(bodyElementIterator.hasNext()) { IBodyElement element = bodyElementIterator.next(); if("TABLE".equalsIgnoreCase(element.getElementType().name())) { List<XWPFTable> tableList = element.getBody().getTables(); //Extract the table row name and their corresponding values from the word stream content tableRowValues = *getTableRowValues*(tableList); } } *Method:* private static ArrayList<String> getTableRowValues(List<XWPFTable> tableList) { ArrayList<String> tableValues = new ArrayList<String>(); for (XWPFTable xwpfTable : tableList) { List<XWPFTableRow> row = xwpfTable.getRows(); for (XWPFTableRow xwpfTableRow : row) { List<XWPFTableCell> cell = xwpfTableRow.getTableCells(); for (XWPFTableCell xwpfTableCell : cell) { List<XWPFParagraph> para = xwpfTableCell.getParagraphs(); for (XWPFParagraph xwpfTablePara : para) { if(xwpfTablePara!=null) { tableValues.add( xwpfTablePara.getText()); } } } } } return tableValues; } -- Sent from: http://apache-poi.1045710.n5.nabble.com/POI-User-f2280730.html --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@poi.apache.org For additional commands, e-mail: user-h...@poi.apache.org