Accessing Existing Tables

From Apache OpenOffice Wiki
Jump to: navigation, search

To access the tables contained in a text document, the text document model supports the interface with one single method getTextTables(). It returns a service, which is a named and indexed collection, that is, tables are retrieved using or

The following snippet iterates over the text tables in a given text document object mxDoc and colors them green.

 // first query the XTextTablesSupplier interface from our document
 XTextTablesSupplier xTablesSupplier = (XTextTablesSupplier) UnoRuntime.queryInterface(
     XTextTablesSupplier.class, mxDoc );
 // get the tables collection
 XNameAccess xNamedTables = xTablesSupplier.getTextTables();
 // now query the XIndexAccess from the tables collection
 XIndexAccess xIndexedTables = (XIndexAccess) UnoRuntime.queryInterface(
     XIndexAccess.class, xNamedTables);
 // we need properties
 XPropertySet xTableProps = null;
 // get the tables
 for (int i = 0; i < xIndexedTables.getCount(); i++) {
     Object table = xIndexedTables.getByIndex(i);
     // the properties, please!
     xTableProps = (XPropertySet) UnoRuntime.queryInterface(
         XPropertySet.class, table);
     // color the table light green in format 0xRRGGBB
     xTableProps.setPropertyValue("BackColor", new Integer(0xC8FFB9));
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages