You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Jefin <pj...@gmail.com> on 2014/02/11 06:30:10 UTC

Re: read table from word document using XWPF in Aapche poi

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: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org