Hi Vasavi,

you can try this code which i had to write for my work, hope it should help
you, incase of any doubts u can write me back 

"
public static void readWordDocument() { 
    try { 
            String fileName = "D:\\EC-4.docx"; 
          
            if(!(fileName.endsWith(".doc") || fileName.endsWith(".docx"))) { 
                    throw new FileFormatException(); 
            } else { 
                        
                        XWPFDocument doc = new XWPFDocument(new
FileInputStream(fileName));
                    
                    List<XWPFTable> table = doc.getTables();        
                    
                    for (XWPFTable xwpfTable : table) {
                                                        List<XWPFTableRow> row 
= xwpfTable.getRows();
                                                        for (XWPFTableRow 
xwpfTableRow : row) {
                                                                
List<XWPFTableCell> cell = xwpfTableRow.getTableCells();
                                                                for 
(XWPFTableCell xwpfTableCell : cell) {
                                                                        
if(xwpfTableCell!=null)
                                                                        {
                                                                                
System.out.println(xwpfTableCell.getText());
                                                                                
List<XWPFTable> itable = xwpfTableCell.getTables();
                                                                                
if(itable.size()!=0)
                                                                                
{
                                                                                
        for (XWPFTable xwpfiTable : itable) {
                                                                                
                List<XWPFTableRow> irow = xwpfiTable.getRows();
                                                                                
                for (XWPFTableRow xwpfiTableRow : irow) {
                                                                                
                        List<XWPFTableCell> icell = 
xwpfiTableRow.getTableCells();
                                                                                
                        for (XWPFTableCell xwpfiTableCell : icell) {
                                                                                
                                if(xwpfiTableCell!=null)
                                                                                
                                {  
                                                                                
                                        
System.out.println(xwpfiTableCell.getText());
                                                                                
                                }
                                                                                
                        }
                                                                                
                }
                                                                                
        }
                                                                                
}
                                                                        }
                                                                }
                                                        }
                        }
                }
    } catch(FileFormatException e) { 
            e.printStackTrace(); 
    } catch (FileNotFoundException e) { 
            e.printStackTrace(); 
    } catch (IOException e) { 
            e.printStackTrace(); 
    } 
   
  }                                             
"



--
View this message in context: 
http://apache-poi.1045710.n5.nabble.com/read-table-from-word-document-using-XWPF-in-Aapche-poi-tp4345743p5714894.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]

Reply via email to