Columns and Rows

From Apache OpenOffice Wiki
Jump to: navigation, search

Collection of table columns:

Collection of table columns

Collection of table rows:

Collection of table rows

The services and represent collections of all columns and rows of a table. It is possible to access cells of columns and rows, and insert and remove columns and rows using the interfaces and that are derived from The method createEnumeration() of the interface creates an enumeration of all columns or rows. The interface accesses columns through their names. The implementation of this interface is optional.

A single column or row is represented by the services and They implement the interfaces that provide access to the cells and for modifying settings. Additionally, the service TableColumn implements the interface It provides the method getName() that returns the name of a column. Changing the name of a column is not supported.

Documentation note.png The interface returns columns and rows relative to the cell range (index 0 is always the first column or row of the cell range). But the interface returns columns with their real names, regardless of the cell range.

In the following example, xColumns is an interface of a collection of columns, xRows is an interface of a collection of rows, and xRange is the range formed by the columns and rows. xPropSet = null;
 // *** Modifying COLUMNS and ROWS ***
 // Get column C by index (interface XIndexAccess).
 Object aColumnObj = xColumns.getByIndex(2);
 xPropSet = (
     UnoRuntime.queryInterface(, aColumnObj);
 xPropSet.setPropertyValue("Width", new Integer(5000));
 // Get the name of the column. xNamed = (
     UnoRuntime.queryInterface(, aColumnObj);
 aText = "The name of this column is " + xNamed.getName() + ".";
 xRange.getCellByPosition(2, 2).setFormula(aText);
 // Get column D by name (interface XNameAccess). xColumnsName = (
     UnoRuntime.queryInterface(, xColumns);
 aColumnObj = xColumnsName.getByName("D");
 xPropSet = (
     UnoRuntime.queryInterface(, aColumnObj);
 xPropSet.setPropertyValue("IsVisible", new Boolean(false));
 // Get row 7 by index (interface XIndexAccess)
 Object aRowObj = xRows.getByIndex(6);
 xPropSet = (
     UnoRuntime.queryInterface(, aRowObj);
 xPropSet.setPropertyValue("Height", new Integer(5000));
 // Create a cell series with the values 1 ... 7.
 for (int nRow = 8; nRow < 15; ++nRow)
     xRange.getCellByPosition( 0, nRow ).setValue( nRow - 7 );
 // Insert a row between 1 and 2
 xRows.insertByIndex(9, 1);
 // Delete the rows with the values 3 and 4.
 xRows.removeByIndex(11, 2); 
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages