1<?xml version="1.0" encoding="UTF-8"?> 2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3<script:module xmlns:script="http://openoffice.org/2000/script" script:name="sheet_XCellRangeMovement" script:language="StarBasic"> 4 5 6'************************************************************************* 7' 8' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 9' 10' Copyright 2000, 2010 Oracle and/or its affiliates. 11' 12' OpenOffice.org - a multi-platform office productivity suite 13' 14' This file is part of OpenOffice.org. 15' 16' OpenOffice.org is free software: you can redistribute it and/or modify 17' it under the terms of the GNU Lesser General Public License version 3 18' only, as published by the Free Software Foundation. 19' 20' OpenOffice.org is distributed in the hope that it will be useful, 21' but WITHOUT ANY WARRANTY; without even the implied warranty of 22' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23' GNU Lesser General Public License version 3 for more details 24' (a copy is included in the LICENSE file that accompanied this code). 25' 26' You should have received a copy of the GNU Lesser General Public License 27' version 3 along with OpenOffice.org. If not, see 28' <http://www.openoffice.org/license.html> 29' for a copy of the LGPLv3 License. 30' 31'************************************************************************* 32'************************************************************************* 33 34 35 36 37 38Sub RunTest() 39 40'************************************************************************* 41' INTERFACE: 42' com.sun.star.sheet.XCellRangeMovement 43'************************************************************************* 44On Error Goto ErrHndl 45 Dim bOK As Boolean 46 47 Out.Log("Prepearing test...") 48 for i = 0 to 5 49 for j = 0 to 5 50 oObj.getCellByPosition(j, i).Value = i * 6 + j 51 next j 52 next i 53 54 Test.StartMethod("insertCells()") 55 bOK = true 56 Dim newCellAddress As New com.sun.star.table.CellRangeAddress 57 newCellAddress.Sheet = 0 58 newCellAddress.StartColumn = 1 59 newCellAddress.StartRow = 1 60 newCellAddress.EndColumn = 1 61 newCellAddress.EndRow = 1 62 oObj.insertCells(newCellAddress, com.sun.star.sheet.CellInsertMode.DOWN) 63 bOK = bOK AND oObj.getCellByPosition(1, 1).String = "" 64 bOK = bOK AND oObj.getCellByPosition(2, 2).Value = 14 65 bOK = bOK AND oObj.getCellByPosition(1, 2).Value = 7 66 bOK = bOK AND oObj.getCellByPosition(0, 2).Value = 12 67 68 oObj.insertCells(newCellAddress, com.sun.star.sheet.CellInsertMode.RIGHT) 69 bOK = bOK AND oObj.getCellByPosition(1, 1).String = "" 70 bOK = bOK AND oObj.getCellByPosition(3, 0).Value = 3 71 bOK = bOK AND oObj.getCellByPosition(3, 1).Value = 8 72 bOK = bOK AND oObj.getCellByPosition(3, 2).Value = 15 73 74 oObj.insertCells(newCellAddress, com.sun.star.sheet.CellInsertMode.ROWS) 75 bOK = bOK AND oObj.getCellByPosition(1, 1).String = "" 76 bOK = bOK AND oObj.getCellByPosition(4, 0).Value = 4 77 bOK = bOK AND oObj.getCellByPosition(4, 1).String = "" 78 bOK = bOK AND oObj.getCellByPosition(4, 2).Value = 9 79 80 oObj.insertCells(newCellAddress, com.sun.star.sheet.CellInsertMode.COLUMNS) 81 bOK = bOK AND oObj.getCellByPosition(1, 1).String = "" 82 bOK = bOK AND oObj.getCellByPosition(0, 5).Value = 24 83 bOK = bOK AND oObj.getCellByPosition(1, 5).String = "" 84 bOK = bOK AND oObj.getCellByPosition(2, 5).Value = 19 85 86 Test.MethodTested("insertCells()", bOK) 87 88 Test.StartMethod("removeRange()") 89 bOK = true 90 oObj.removeRange(newCellAddress, com.sun.star.sheet.CellDeleteMode.ROWS) 91 bOK = bOK AND oObj.getCellByPosition(1, 1).String = "" 92 bOK = bOK AND oObj.getCellByPosition(4, 0).Value = 3 93 bOK = bOK AND oObj.getCellByPosition(4, 1).Value = 8 94 bOK = bOK AND oObj.getCellByPosition(4, 2).Value = 15 95 96 oObj.removeRange(newCellAddress, com.sun.star.sheet.CellDeleteMode.COLUMNS) 97 bOK = bOK AND oObj.getCellByPosition(1, 1).String = "" 98 bOK = bOK AND oObj.getCellByPosition(4, 0).Value = 4 99 bOK = bOK AND oObj.getCellByPosition(4, 1).Value = 9 100 bOK = bOK AND oObj.getCellByPosition(4, 2).Value = 16 101 102 oObj.removeRange(newCellAddress, com.sun.star.sheet.CellDeleteMode.UP) 103 bOK = bOK AND oObj.getCellByPosition(1, 1).Value = 7 104 bOK = bOK AND oObj.getCellByPosition(1, 2).Value = 13 105 bOK = bOK AND oObj.getCellByPosition(1, 3).Value = 19 106 bOK = bOK AND oObj.getCellByPosition(0, 3).Value = 18 107 108 oObj.removeRange(newCellAddress, com.sun.star.sheet.CellDeleteMode.LEFT) 109 bOK = bOK AND oObj.getCellByPosition(1, 1).String = "" 110 bOK = bOK AND oObj.getCellByPosition(0, 1).Value = 6 111 bOK = bOK AND oObj.getCellByPosition(1, 1).String = "" 112 bOK = bOK AND oObj.getCellByPosition(2, 1).Value = 8 113 114 Test.MethodTested("removeRange()", bOK) 115 116 Test.StartMethod("moveRange()") 117 bOK = true 118 newCellAddress.Sheet = 0 119 newCellAddress.StartColumn = 0 120 newCellAddress.StartRow = 0 121 newCellAddress.EndColumn = 1 122 newCellAddress.EndRow = 1 123 Dim sCell As New com.sun.star.table.CellAddress 124 sCell.Sheet = 0 125 sCell.Column = 3 126 sCell.Row = 3 127 oObj.moveRange(sCell, newCellAddress) 128 129 bOK = bOK AND oObj.getCellByPosition(0, 0).String = "" 130 bOK = bOK AND oObj.getCellByPosition(1, 0).String = "" 131 bOK = bOK AND oObj.getCellByPosition(0, 1).String = "" 132 bOK = bOK AND oObj.getCellByPosition(1, 1).String = "" 133 134 bOK = bOK AND oObj.getCellByPosition(3, 3).Value = 0 135 bOK = bOK AND oObj.getCellByPosition(3, 4).Value = 6 136 bOK = bOK AND oObj.getCellByPosition(4, 3).Value = 1 137 bOK = bOK AND oObj.getCellByPosition(4, 4).String = "" 138 139 Test.MethodTested("moveRange()", bOK) 140 141 Test.StartMethod("copyRange()") 142 bOK = true 143 newCellAddress.Sheet = 0 144 newCellAddress.StartColumn = 2 145 newCellAddress.StartRow = 2 146 newCellAddress.EndColumn = 3 147 newCellAddress.EndRow = 3 148 sCell.Sheet = 0 149 sCell.Column = 0 150 sCell.Row = 0 151 152 oObj.copyRange(sCell, newCellAddress) 153 154 bOK = bOK AND oObj.getCellByPosition(0, 0).Value = oObj.getCellByPosition(2, 2).Value 155 bOK = bOK AND oObj.getCellByPosition(0, 1).Value = oObj.getCellByPosition(2, 3).Value 156 bOK = bOK AND oObj.getCellByPosition(1, 0).Value = oObj.getCellByPosition(3, 2).Value 157 bOK = bOK AND oObj.getCellByPosition(1, 1).Value = oObj.getCellByPosition(3, 3).Value 158 159 Test.MethodTested("copyRange()", bOK) 160 161Exit Sub 162ErrHndl: 163 Test.Exception() 164 bOK = false 165 resume next 166End Sub 167</script:module> 168