Difference between revisions of "Documentation/DevGuide/Text/Accessing Existing Tables"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (Robot: Changing Category:Documentation/Developers Guide/Text Documents)
m (FINAL VERSION FOR L10N)
Line 6: Line 6:
 
|NextPage=Documentation/DevGuide/Text/Text Fields
 
|NextPage=Documentation/DevGuide/Text/Text Fields
 
}}
 
}}
{{DISPLAYTITLE:Accessing Existing Tables}}
+
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Text/{{SUBPAGENAME}}}}
 +
{{DISPLAYTITLE:Accessing Existing Tables}}
 
To access the tables contained in a text document, the text document model supports the interface <idl>com.sun.star.text.XTextTablesSupplier</idl> with one single method <code>getTextTables()</code>. It returns a <idl>com.sun.star.text.TextTables</idl> service, which is a named and indexed collection, that is, tables are retrieved using <idl>com.sun.star.container.XNameAccess</idl> or <idl>com.sun.star.container.XIndexAccess</idl>.
 
To access the tables contained in a text document, the text document model supports the interface <idl>com.sun.star.text.XTextTablesSupplier</idl> with one single method <code>getTextTables()</code>. It returns a <idl>com.sun.star.text.TextTables</idl> service, which is a named and indexed collection, that is, tables are retrieved using <idl>com.sun.star.container.XNameAccess</idl> or <idl>com.sun.star.container.XIndexAccess</idl>.
  

Revision as of 10:09, 14 May 2009



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

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

 import com.sun.star.text.XTextTablesSupplier;
 import com.sun.star.container.XNameAccess;
 import com.sun.star.container.XIndexAccess;
 import com.sun.star.beans.XPropertySet;
 
 ...
 
 // 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