All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.docx4j.finders.TcFinder Maven / Gradle / Ivy

Go to download

docx4j is a library which helps you to work with the Office Open XML file format as used in docx documents, pptx presentations, and xlsx spreadsheets.

There is a newer version: 6.1.2
Show newest version
package org.docx4j.finders;

import java.util.ArrayList;
import java.util.List;

import org.docx4j.TraversalUtil.CallbackImpl;
import org.docx4j.wml.Tbl;
import org.docx4j.wml.Tc;

public class  TcFinder extends CallbackImpl {
	
	boolean traveseTables=false;
	
	/**
	 * Defaults to false; set this to true unless you don't
	 * want to traverse a table (eg a nested table).
	 * NB: If traversing from body level, you'll need to set it to true!
	 * 
	 * @param traveseNestedTable
	 */
	public void setTraverseTables(boolean traveseTables) {
		this.traveseTables = traveseTables;
	}

	public List tcList = new ArrayList();  
			
	@Override
	public List apply(Object o) {
		
		if (o instanceof Tc ) {
			tcList.add((Tc)o);
		}			
		return null; 
	}
	
	@Override
	public boolean shouldTraverse(Object o) {
		
		if (traveseTables) {
			return true;
		} else {
			// Yes, unless its a nested Tbl
			return !(o instanceof Tbl);
		}
	}
}