You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by shyam <sh...@gmail.com> on 2017/10/05 09:17:19 UTC

Table Content Extraction Section wise in .docx file

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


Re: Table Content Extraction Section wise in .docx file

Posted by Javen O'Neal <on...@apache.org>.
I don't understand your question well enough to suggest anything specific,
but it looks like you're on the right track. Add a few conditionals to
process the sections you're interested in.

On a different note, you may want to upgrade to POI 3.17, as quite a few
security updates, bug fixes, and new features have been added since POI 3.9.

Sorry I couldn't be of more help. My familiarity is mostly with XSSF, and
not so much with XWPF.

On Oct 8, 2017 22:39, "shyam" <sh...@gmail.com> wrote:

> Could anyone please help?
>
>
>
> --
> Sent from: http://apache-poi.1045710.n5.nabble.com/POI-User-f2280730.html
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>

Re: Table Content Extraction Section wise in .docx file

Posted by shyam <sh...@gmail.com>.
Could anyone please help?



--
Sent from: http://apache-poi.1045710.n5.nabble.com/POI-User-f2280730.html

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org