Columns and Rows

From Apache OpenOffice Wiki
< Documentation‎ | DevGuide
Revision as of 16:20, 4 July 2018 by Sancho (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search



Collection of table columns:

Collection of table columns

Collection of table rows:

Collection of table rows

The services com.sun.star.table.TableColumns and com.sun.star.table.TableRows 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 com.sun.star.table.XTableColumns and com.sun.star.table.XTableRows that are derived from com.sun.star.container.XIndexAccess. The method createEnumeration() of the interface com.sun.star.container.XEnumerationAccess creates an enumeration of all columns or rows. The interface com.sun.star.container.XNameAccess accesses columns through their names. The implementation of this interface is optional.

A single column or row is represented by the services com.sun.star.table.TableColumn and com.sun.star.table.TableRow. They implement the interfaces com.sun.star.table.XCellRange that provide access to the cells and com.sun.star.beans.XPropertySet for modifying settings. Additionally, the service TableColumn implements the interface com.sun.star.container.XNamed. 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 com.sun.star.container.XIndexAccess 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 com.sun.star.container.XNameAccess 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.

 com.sun.star.beans.XPropertySet xPropSet = null;
 
 // *** Modifying COLUMNS and ROWS ***
 // Get column C by index (interface XIndexAccess).
 Object aColumnObj = xColumns.getByIndex(2);
 xPropSet = (com.sun.star.beans.XPropertySet)
     UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, aColumnObj);
 xPropSet.setPropertyValue("Width", new Integer(5000));
 
 // Get the name of the column.
 com.sun.star.container.XNamed xNamed = (com.sun.star.container.XNamed)
     UnoRuntime.queryInterface(com.sun.star.container.XNamed.class, aColumnObj);
 aText = "The name of this column is " + xNamed.getName() + ".";
 xRange.getCellByPosition(2, 2).setFormula(aText);
 
 // Get column D by name (interface XNameAccess).
 com.sun.star.container.XNameAccess xColumnsName = (com.sun.star.container.XNameAccess)
     UnoRuntime.queryInterface(com.sun.star.container.XNameAccess.class, xColumns);
 
 aColumnObj = xColumnsName.getByName("D");
 xPropSet = (com.sun.star.beans.XPropertySet)
     UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, aColumnObj);
 xPropSet.setPropertyValue("IsVisible", new Boolean(false));
 
 // Get row 7 by index (interface XIndexAccess)
 Object aRowObj = xRows.getByIndex(6);
 xPropSet = (com.sun.star.beans.XPropertySet)
     UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, 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