Difference between revisions of "Documentation/DevGuide/Spreadsheets/Columns and Rows"

From Apache OpenOffice Wiki
Jump to: navigation, search
(Initial author Sun Microsystems, Inc.)
 
m (1 revision(s))
(No difference)

Revision as of 13:05, 15 February 2008



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.

Template:Documentation/Note

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