XTextTable row height

Creating a macro - Writing a Script - Using the API

XTextTable row height

Postby alex157 » Tue Jul 03, 2018 3:06 am

I created an empty table in a .odt document (see attached document) and I have tried using the following code to get the row height for the first row. However, it is returning a height of 0. How can I get the heights of the rows (or the dimensions of the cells as indicated by their boundaries)?
Code: Select all   Expand viewCollapse view
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));
        } catch( Exception e ) {
(8.69 KiB) Downloaded 23 times
Open Office 4.1.5
Posts: 2
Joined: Tue Jul 03, 2018 2:48 am

Re: XTextTable row height

Postby hubert lambert » Tue Jul 03, 2018 12:05 pm


Height is actually 0. But as long as the property 'IsAutoHeight' is True, row height is automatically adjusted to font height, border margins...
I don't know any api interface that returns the "effective" computed row height.

AOOo 4.1.2 on Win7 | LibreOffice on various Linux systems
hubert lambert
Posts: 123
Joined: Mon Jun 13, 2016 10:50 am

Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 8 guests