Table Content Extraction Section wise in .docx file

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Table Content Extraction Section wise in .docx file

shyam
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Table Content Extraction Section wise in .docx file

shyam
Could anyone please help?



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

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Table Content Extraction Section wise in .docx file

Javen O'Neal-2
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" <[hidden email]> wrote:

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