Difference between revisions of "Documentation/DevGuide/Spreadsheets/Spreadsheet"

From Apache OpenOffice Wiki
Jump to: navigation, search
(Page Breaks)
 
Line 59: Line 59:
 
The following example copies a cell range to another location in the sheet.  
 
The following example copies a cell range to another location in the sheet.  
 
<!--[SOURCE:Spreadsheet/SpreadsheetSample.java]-->
 
<!--[SOURCE:Spreadsheet/SpreadsheetSample.java]-->
<source lang="java">
+
<syntaxhighlight lang="java">
 
   /** Copies a cell range to another place in the sheet.
 
   /** Copies a cell range to another place in the sheet.
 
       @param xSheet The XSpreadsheet interface of the spreadsheet.
 
       @param xSheet The XSpreadsheet interface of the spreadsheet.
Line 71: Line 71:
 
           UnoRuntime.queryInterface(com.sun.star.sheet.XCellRangeMovement.class, xSheet);
 
           UnoRuntime.queryInterface(com.sun.star.sheet.XCellRangeMovement.class, xSheet);
 
       xMovement.copyRange(aDestCell, aSourceRange);
 
       xMovement.copyRange(aDestCell, aSourceRange);
   }</source>
+
   }
 +
</syntaxhighlight>
  
 
=== Page Breaks ===
 
=== Page Breaks ===
Line 80: Line 81:
 
The following example prints the positions of all the automatic column page breaks:  
 
The following example prints the positions of all the automatic column page breaks:  
 
<!--[SOURCE:Spreadsheet/SpreadsheetSample.java]-->
 
<!--[SOURCE:Spreadsheet/SpreadsheetSample.java]-->
<source lang="java">
+
<syntaxhighlight lang="java">
 
   // --- Print automatic column page breaks ---
 
   // --- Print automatic column page breaks ---
 
   com.sun.star.sheet.XSheetPageBreak xPageBreak = (com.sun.star.sheet.XSheetPageBreak)
 
   com.sun.star.sheet.XSheetPageBreak xPageBreak = (com.sun.star.sheet.XSheetPageBreak)
Line 90: Line 91:
 
       if (!aPageBreakArray[nIndex].ManualBreak)
 
       if (!aPageBreakArray[nIndex].ManualBreak)
 
           System.out.print( " " + aPageBreakArray[nIndex].Position);
 
           System.out.print( " " + aPageBreakArray[nIndex].Position);
   System.out.println();</source>
+
   System.out.println();
 +
</syntaxhighlight>
  
 
{{PDL1}}
 
{{PDL1}}
  
 
[[Category:Documentation/Developer's Guide/Spreadsheet Documents]]
 
[[Category:Documentation/Developer's Guide/Spreadsheet Documents]]

Latest revision as of 15:19, 3 January 2021



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

IsVisible

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

PageStyle

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

Naming

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

insertCells()

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).

removeRange()

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

copyRange()

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

moveRange()

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);
  System.out.println();
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages