You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by vasavi <va...@gmail.com> on 2011/09/21 15:30:00 UTC

read nested tables data from word document using java

I have a word document with 2 nested tables in that. when i am trying to read
that data, i got only  outer table data . I am using  POIFSFileSystem.

How can i get that inner table data.

--
View this message in context: http://apache-poi.1045710.n5.nabble.com/read-nested-tables-data-from-word-document-using-java-tp4826333p4826333.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


Re: read nested tables data from word document using java

Posted by vasavi <va...@gmail.com>.
i am using POI 3.8 beta 2


--
View this message in context: http://apache-poi.1045710.n5.nabble.com/read-nested-tables-data-from-word-document-using-java-tp4826333p4829778.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


Re: read nested tables data from word document using java

Posted by Nick Burch <ni...@alfresco.com>.
On Thu, 22 Sep 2011, vasavi wrote:
> I have table in 4 row .that small table have 2 cells.
>
>
>                       Paragraph   tab=row.getParagraph(0);
> 	              Table t=row.getTable(tab);
>                      System.out.println("number of rows "+t.NumRows());
>
> when i am try to print this it shows The end (80) must not be before the
> start (106)

Did you try with POI 3.8 beta 4? Sergey has been doing some great work 
lately fixing HWPF bugs, so that problem may be fixed

Nick

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


Re: read nested tables data from word document using java

Posted by vasavi <va...@gmail.com>.
I Tried like this,

I have table in 4 row .that small table have 2 cells.


                       Paragraph   tab=row.getParagraph(0);
	              Table t=row.getTable(tab);
                      System.out.println("number of rows "+t.NumRows());   

when i am try to print this it shows The end (80) must not be before the
start (106)

how to set paragraph value ,for second table


import java.io.*;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.poi.POIOLE2TextExtractor;
import org.apache.poi.extractor.ExtractorFactory;
import org.apache.poi.hpsf.*;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.extractor.WordExtractor;
import org.apache.poi.hwpf.usermodel.Paragraph;
import org.apache.poi.hwpf.usermodel.Range;
import org.apache.poi.hwpf.usermodel.Table;
import org.apache.poi.hwpf.usermodel.TableCell;
import org.apache.poi.hwpf.usermodel.TableRow;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

import excel.Workbook;
 
public class readwordIMP
{
	public readwordIMP()
	{
		 Table table = null;
		 TableRow  row = null;
		 String filesname = "D:\\Akhil\\TEMP\\maths\\limits and contin\\Limits - 1
- Assignment Info\\IITPU1_M_11_1_M.doc";

		 ArrayList<String> al=new ArrayList<String>();
		try
		{
		  POIFSFileSystem fs = new POIFSFileSystem(new
FileInputStream(filesname));                 
                  HWPFDocument doc = new HWPFDocument(fs);         
		  String character;	
		  Range range = doc.getRange();
		  
		  Paragraph tablePar;
		  tablePar = range.getParagraph(0);
		
	       if (isInTable()) {
	             table = range.getTable(tablePar);
	         
	            for (int rowIdx=4; rowIdx<table.numRows(); rowIdx++)
	            {
	            	row = table.getRow(rowIdx);	    
	                System.out.println("row
"+(rowIdx+1)+"qwwq"+row.numCells());
                        
 ****               Paragraph   tab=row.getParagraph(0);
	              Table t=row.getTable(tab);
                      System.out.println("number of rows "+t.NumRows());          
**************


	          //      for (int colIdx=0; colIdx<row.numCells(); colIdx++) 
	            //    {
	              //       TableCell cell = row.getCell(colIdx);
	                //     character=cell.getParagraph(0).text();

                              
         
	                  //   character=character.substring(0,
character.length()-1);	                    

	                    // al.add(character);
	                    
	                //}
	              }         
	        }
	        
          } catch(Exception e) { 
                    e.printStackTrace();
                }
	}
	private Paragraph Paragraph(int i) {
		// TODO Auto-generated method stub
		return null;
	}
	private boolean isInTable() {
		// TODO Auto-generated method stub
		return true;
	}
	public static void main( String[] args )
	{
		readwordIMP t=new readwordIMP();		
    }
}


--
View this message in context: http://apache-poi.1045710.n5.nabble.com/read-nested-tables-data-from-word-document-using-java-tp4826333p4829697.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


Re: read nested tables data from word document using java

Posted by Nick Burch <ni...@alfresco.com>.
On Wed, 21 Sep 2011, vasavi wrote:
> I have a word document with 2 nested tables in that. when i am trying to read
> that data, i got only  outer table data .

In the cell that contains the inner table, you should be able to fetch the 
inner table. Get the paragraph of the cell, and call getTable on it just 
as you would for the outer one

paragraph.getTableLevel() is also handy here, as it lets you check the 
level of nesting

Nick

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