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

From Apache OpenOffice Wiki
Jump to: navigation, search
m (1 revision(s))
(3 intermediate revisions by one other user not shown)
Line 6: Line 6:
 
|NextPage=Documentation/DevGuide/Spreadsheets/Formatting
 
|NextPage=Documentation/DevGuide/Spreadsheets/Formatting
 
}}
 
}}
{{DISPLAYTITLE:Columns and Rows}}
+
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Spreadsheets/{{SUBPAGENAME}}}}
 +
{{DISPLAYTITLE:Columns and Rows}}
 
<!--<idltopic>com.sun.star.table.TableColumns;com.sun.star.table.TableRows</idltopic>-->
 
<!--<idltopic>com.sun.star.table.TableColumns;com.sun.star.table.TableRows</idltopic>-->
 
Collection of table columns:
 
Collection of table columns:
Line 20: Line 21:
 
A single column or row is represented by the services <idl>com.sun.star.table.TableColumn</idl> and <idl>com.sun.star.table.TableRow</idl>. They implement the interfaces <idl>com.sun.star.table.XCellRange</idl> that provide access to the cells and <idl>com.sun.star.beans.XPropertySet</idl> for modifying settings. Additionally, the service <code>TableColumn</code> implements the interface <idl>com.sun.star.container.XNamed</idl>. It provides the method <code>getName()</code> that returns the name of a column. Changing the name of a column is not supported.
 
A single column or row is represented by the services <idl>com.sun.star.table.TableColumn</idl> and <idl>com.sun.star.table.TableRow</idl>. They implement the interfaces <idl>com.sun.star.table.XCellRange</idl> that provide access to the cells and <idl>com.sun.star.beans.XPropertySet</idl> for modifying settings. Additionally, the service <code>TableColumn</code> implements the interface <idl>com.sun.star.container.XNamed</idl>. It provides the method <code>getName()</code> that returns the name of a column. Changing the name of a column is not supported.
  
{{Documentation/Note|The interface <idl>com.sun.star.container.XIndexAccess</idl> 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 <idl>com.sun.star.container.XNameAccess</idl> returns columns with their real names, regardless of the cell range.}}
+
{{Note|The interface <idl>com.sun.star.container.XIndexAccess</idl> 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 <idl>com.sun.star.container.XNameAccess</idl> returns columns with their real names, regardless of the cell range.}}
  
 
In the following example, <code>xColumns</code> is an interface of a collection of columns, <code>xRows</code> is an interface of a collection of rows, and <code>xRange</code> is the range formed by the columns and rows.  
 
In the following example, <code>xColumns</code> is an interface of a collection of columns, <code>xRows</code> is an interface of a collection of rows, and <code>xRange</code> is the range formed by the columns and rows.  
Line 64: Line 65:
  
 
{{PDL1}}
 
{{PDL1}}
[[Category: Spreadsheet Documents]]
+
 
 +
[[Category:Documentation/Developer's Guide/Spreadsheet Documents]]

Revision as of 16:20, 4 July 2018



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