Difference between revisions of "Documentation/DevGuide/Text/Accessing Existing Tables"
From Apache OpenOffice Wiki
< Documentation | DevGuide
OOoWikiBot (talk | contribs) m (FINAL VERSION FOR L10N) |
|||
| Line 11: | Line 11: | ||
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 42: | Line 42: | ||
xTableProps.setPropertyValue("BackColor", new Integer(0xC8FFB9)); | xTableProps.setPropertyValue("BackColor", new Integer(0xC8FFB9)); | ||
} | } | ||
| − | + | </syntaxhighlight> | |
{{PDL1}} | {{PDL1}} | ||
[[Category:Documentation/Developer's Guide/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). |