From Apache OpenOffice Wiki
Jump to: navigation, search

A spreadsheet is a cell range with additional interfaces and is represented by the service com.sun.star.sheet.Spreadsheet.

Properties of Spreadsheet

The properties of a spreadsheet deal with its visibility and its page style:

Properties of com.sun.star.sheet.Spreadsheet


boolean - Determines if the sheet is visible in the GUI.


Contains the name of the page style of this spreadsheet. See Overall Document Features for details about styles.


The spreadsheet interface com.sun.star.container.XNamed obtains and changes the name of the spreadsheet, and uses it to get a spreadsheet from the spreadsheet collection. Refer to Spreadsheet Documents.

Inserting Cells, Moving and Copying Cell Ranges

The interface com.sun.star.sheet.XCellRangeMovement of the Spreadsheet service supports inserting and removing cells from a spreadsheet, and copying and moving cell contents. When cells are copied or moved, the relative references of all formulas are updated automatically. The sheet index included in the source range addresses should be equal to the index of the sheet of this interface.

Methods of com.sun.star.sheet.XCellRangeMovement


Inserts a range of empty cells at a specific position. The direction of the insertion is determined by the parameter nMode (type com.sun.star.sheet.CellInsertMode).


Deletes a range of cells from the spreadsheet. The parameter nMode (type com.sun.star.sheet.CellDeleteMode) determines how remaining cells will be moved.


Copies the contents of a cell range to another place in the document.


Moves the contents of a cell range to another place in the document. Deletes all contents of the source range.

The following example copies a cell range to another location in the sheet.

  /** Copies a cell range to another place in the sheet.
      @param xSheet The XSpreadsheet interface of the spreadsheet.
      @param aDestCell The address of the first cell of the destination range.
      @param aSourceRange The source range address.
  public void doMovementExample(com.sun.star.sheet.XSpreadsheet xSheet,
          com.sun.star.table.CellAddress aDestCell, com.sun.star.table.CellRangeAddress aSourceRange)
          throws RuntimeException, Exception {
      com.sun.star.sheet.XCellRangeMovement xMovement = (com.sun.star.sheet.XCellRangeMovement)
          UnoRuntime.queryInterface(com.sun.star.sheet.XCellRangeMovement.class, xSheet);
      xMovement.copyRange(aDestCell, aSourceRange);

Page Breaks

The methods getColumnPageBreaks() and getRowPageBreaks() of the interface com.sun.star.sheet.XSheetPageBreak return the positions of column and row page breaks, represented by a sequence of com.sun.star.sheet.TablePageBreakData structs. Each struct contains the position of the page break and a boolean property that determines if the page break was inserted manually. Inserting and removing a manual page break uses the property IsStartOfNewPage of the services com.sun.star.table.TableColumn and com.sun.star.table.TableRow.

The following example prints the positions of all the automatic column page breaks:

  // --- Print automatic column page breaks ---
  com.sun.star.sheet.XSheetPageBreak xPageBreak = (com.sun.star.sheet.XSheetPageBreak)
      UnoRuntime.queryInterface(com.sun.star.sheet.XSheetPageBreak.class, xSheet);
  com.sun.star.sheet.TablePageBreakData[] aPageBreakArray = xPageBreak.getColumnPageBreaks();
  System.out.print("Automatic column page breaks:");
  for (int nIndex = 0; nIndex < aPageBreakArray.length; ++nIndex)
      if (!aPageBreakArray[nIndex].ManualBreak)
          System.out.print( " " + aPageBreakArray[nIndex].Position);
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages