Code: Select all
import com.sun.star.uno.UnoRuntime;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.uno.XComponentContext;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lang.XComponent;
import com.sun.star.comp.helper.Bootstrap;
import com.sun.star.beans.PropertyValue;
import com.sun.star.frame.FrameSearchFlag;
import com.sun.star.text.XTextTablesSupplier;
import com.sun.star.container.XNameAccess;
import com.sun.star.container.XIndexAccess;
import com.sun.star.beans.XPropertySet;
import com.sun.star.text.XTextTable;
import com.sun.star.uno.Any;
import com.sun.star.table.XTableRows;
import java.io.File;
public class Test1 {
public static void main( String args[] ) {
try {
XComponentContext xContext = Bootstrap.bootstrap();
XMultiComponentFactory xMCF = xContext.getServiceManager();
Object oDesktop = xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext);
XComponentLoader xCompLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, oDesktop);
File file = new File("split_table1.odt");
String path = file.getAbsolutePath();
String sUrl = "file://" + path;
PropertyValue propertyValues[] = new PropertyValue[1];
propertyValues[0] = new PropertyValue();
propertyValues[0].Name = "Hidden";
propertyValues[0].Value = new Boolean(true);
XComponent xdoc = xCompLoader.loadComponentFromURL(sUrl, "_blank", FrameSearchFlag.ALL, propertyValues);
XTextTablesSupplier xTablesSupplier = (XTextTablesSupplier) UnoRuntime.queryInterface(XTextTablesSupplier.class, xdoc);
XNameAccess xNamedTables = xTablesSupplier.getTextTables();
XIndexAccess xIndexedTables = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xNamedTables);
Any any = (Any) xIndexedTables.getByIndex(0);
XTextTable xtable = (XTextTable) any.getObject();
XTableRows rows = (XTableRows) xtable.getRows();
XIndexAccess xIndexedRows = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, rows);
any = (Any) xIndexedRows.getByIndex(0);
XPropertySet xrow = (XPropertySet) any.getObject();
Integer height = (Integer) xrow.getPropertyValue("Height");
System.out.println("height: " + Integer.toString(height));
System.exit(0);
} catch( Exception e ) {
e.printStackTrace(System.err);
}
}
}