XTextTable row height

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
alex157
Posts: 2
Joined: Tue Jul 03, 2018 2:48 am

XTextTable row height

Post by alex157 »

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

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);                    
        }
    }
}
Attachments
split_table1.odt
(8.69 KiB) Downloaded 97 times
Open Office 4.1.5
Linux
hubert lambert
Posts: 145
Joined: Mon Jun 13, 2016 10:50 am

Re: XTextTable row height

Post by hubert lambert »

Hi,

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.

Regards.
AOOo 4.1.2 on Win7 | LibreOffice on various Linux systems
Post Reply