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

From Apache OpenOffice Wiki
Jump to: navigation, search
(Initial author Sun Microsystems, Inc.)
 
 
(4 intermediate revisions by 2 users not shown)
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>.
  
 
The following snippet iterates over the text tables in a given text document object <code>mxDoc</code> and colors them green.
 
The following snippet iterates over the text tables in a given text document object <code>mxDoc</code> and colors them green.
 
+
<syntaxhighlight lang="java">
 
   import com.sun.star.text.XTextTablesSupplier;
 
   import com.sun.star.text.XTextTablesSupplier;
 
   import com.sun.star.container.XNameAccess;
 
   import com.sun.star.container.XNameAccess;
Line 41: Line 42:
 
       xTableProps.setPropertyValue("BackColor", new Integer(0xC8FFB9));
 
       xTableProps.setPropertyValue("BackColor", new Integer(0xC8FFB9));
 
   }  
 
   }  
 
+
</syntaxhighlight>
 
{{PDL1}}
 
{{PDL1}}
[[Category: Text Documents]]
+
 
 +
[[Category:Documentation/Developer's Guide/Text Documents]]

Latest revision as of 14:11, 3 January 2021



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