1cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?> 2cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="table_XCellRange" script:language="StarBasic"> 4cdf0e10cSrcweir 5cdf0e10cSrcweir 6cdf0e10cSrcweir'************************************************************************* 7cdf0e10cSrcweir' 8*eebed415SAndrew Rist' Licensed to the Apache Software Foundation (ASF) under one 9*eebed415SAndrew Rist' or more contributor license agreements. See the NOTICE file 10*eebed415SAndrew Rist' distributed with this work for additional information 11*eebed415SAndrew Rist' regarding copyright ownership. The ASF licenses this file 12*eebed415SAndrew Rist' to you under the Apache License, Version 2.0 (the 13*eebed415SAndrew Rist' "License"); you may not use this file except in compliance 14*eebed415SAndrew Rist' with the License. You may obtain a copy of the License at 15*eebed415SAndrew Rist' 16*eebed415SAndrew Rist' http://www.apache.org/licenses/LICENSE-2.0 17*eebed415SAndrew Rist' 18*eebed415SAndrew Rist' Unless required by applicable law or agreed to in writing, 19*eebed415SAndrew Rist' software distributed under the License is distributed on an 20*eebed415SAndrew Rist' "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 21*eebed415SAndrew Rist' KIND, either express or implied. See the License for the 22*eebed415SAndrew Rist' specific language governing permissions and limitations 23*eebed415SAndrew Rist' under the License. 24cdf0e10cSrcweir' 25cdf0e10cSrcweir'************************************************************************* 26cdf0e10cSrcweir 27cdf0e10cSrcweir 28cdf0e10cSrcweir 29*eebed415SAndrew Rist 30*eebed415SAndrew Rist 31cdf0e10cSrcweir' Be sure that all variables are dimensioned: 32cdf0e10cSrcweiroption explicit 33cdf0e10cSrcweir 34cdf0e10cSrcweir'************************************************************************* 35cdf0e10cSrcweir' You can only get ranges within your 36cdf0e10cSrcweir' object-range. That means is your object-range 37cdf0e10cSrcweir' is (A1:C3) you can get only a range within 38cdf0e10cSrcweir' (A1:C3). 39cdf0e10cSrcweir 40cdf0e10cSrcweir'************************************************************************* 41cdf0e10cSrcweir 42cdf0e10cSrcweir 43cdf0e10cSrcweir 44cdf0e10cSrcweir 45cdf0e10cSrcweir 46cdf0e10cSrcweirSub RunTest() 47cdf0e10cSrcweir 48cdf0e10cSrcweir'************************************************************************* 49cdf0e10cSrcweir' INTERFACE: 50cdf0e10cSrcweir' com.sun.star.table.XCellRange 51cdf0e10cSrcweir'************************************************************************* 52cdf0e10cSrcweirOn Error Goto ErrHndl 53cdf0e10cSrcweir Dim bOK As Boolean 54cdf0e10cSrcweir 55cdf0e10cSrcweir Dim oCell As Object 56cdf0e10cSrcweir Dim oCellRange As Object 57cdf0e10cSrcweir Dim oCellRange1 As Object 58cdf0e10cSrcweir Dim bSupport As Boolean 59cdf0e10cSrcweir Dim oAddress As Object 60cdf0e10cSrcweir Dim nSCol As Long, nECol As Long 61cdf0e10cSrcweir Dim nSRow As Long, nERow As Long 62cdf0e10cSrcweir Dim nCol As Long, nRow As Long 63cdf0e10cSrcweir Dim cSCol As String, cECol As String 64cdf0e10cSrcweir 65cdf0e10cSrcweir bOK = true 66cdf0e10cSrcweir 'does the object support this service? If yes, the object is a range itself. 67cdf0e10cSrcweir 'So we must look for the range address to be get a valid range 68cdf0e10cSrcweir if hasUnoInterfaces( oObj, "com.sun.star.sheet.XCellRangeAddressable" ) then 69cdf0e10cSrcweir Out.Log("Object supports com.sun.star.sheet.XCellRangeAddressable") 70cdf0e10cSrcweir bSupport = true 71cdf0e10cSrcweir oAddress = oObj.getRangeAddress() 72cdf0e10cSrcweir nSCol = oAddress.StartColumn 73cdf0e10cSrcweir nECol = oAddress.EndColumn 74cdf0e10cSrcweir nSRow = oAddress.StartRow 75cdf0e10cSrcweir nERow = oAddress.EndRow 76cdf0e10cSrcweir nCol = nECol - nSCol 77cdf0e10cSrcweir nRow = nERow - nSRow 78cdf0e10cSrcweir else 79cdf0e10cSrcweir bSupport = false 80cdf0e10cSrcweir nCol = 1 81cdf0e10cSrcweir nRow = 1 82cdf0e10cSrcweir end if 83cdf0e10cSrcweir 84cdf0e10cSrcweir Test.StartMethod("getCellByPosition()") 85cdf0e10cSrcweir bOK = true 86cdf0e10cSrcweir Out.Log("try to getCellByPosition(" + nCol + "," + nRow + ")") 87cdf0e10cSrcweir oCell = oObj.getCellByPosition(nCol, nRow) 88cdf0e10cSrcweir bOK = bOK AND hasUnoInterfaces( oCell, "com.sun.star.table.XCell" ) 89cdf0e10cSrcweir Test.MethodTested("getCellByPosition()", bOK) 90cdf0e10cSrcweir 91cdf0e10cSrcweir Test.StartMethod("getCellRangeByPosition()") 92cdf0e10cSrcweir bOK = true 93cdf0e10cSrcweir Out.Log("try to getCellRangeByPosition(0,0," + nCol + "," + nRow + ")") 94cdf0e10cSrcweir oCellRange = oObj.getCellRangeByPosition(0, 0, nCol, nRow) 95cdf0e10cSrcweir bOK = bOK AND hasUnoInterfaces( oCellRange, "com.sun.star.table.XCellRange" ) 96cdf0e10cSrcweir Test.MethodTested("getCellRangeByPosition()", bOK) 97cdf0e10cSrcweir 98cdf0e10cSrcweir Test.StartMethod("getCellRangeByName()") 99cdf0e10cSrcweir bOK = true 100cdf0e10cSrcweir if bSupport then 101cdf0e10cSrcweir oAddress = oObj.getRangeAddress() 102cdf0e10cSrcweir nSCol = oAddress.StartColumn 103cdf0e10cSrcweir nECol = oAddress.EndColumn 104cdf0e10cSrcweir nSRow = oAddress.StartRow 105cdf0e10cSrcweir nERow = oAddress.EndRow 106cdf0e10cSrcweir cSCol = getCharacter(nSCol) 107cdf0e10cSrcweir cECol = getCharacter(nECol) 108cdf0e10cSrcweir else 109cdf0e10cSrcweir nSRow = 0 110cdf0e10cSrcweir nERow = 2 111cdf0e10cSrcweir cSCol = "A" 112cdf0e10cSrcweir cECol = "C" 113cdf0e10cSrcweir end if 114cdf0e10cSrcweir Out.Log("Try to getCellRangeByName(""" + cSCol + (nSRow + 1) + ":" + cECol + (nERow + 1) + """)") 115cdf0e10cSrcweir oCellRange1 = oObj.getCellRangeByName("" + cSCol + (nSRow + 1) + ":" + cECol + (nERow + 1)) 116cdf0e10cSrcweir bOK = bOK AND hasUnoInterfaces( oCellRange1, "com.sun.star.table.XCellRange" ) 117cdf0e10cSrcweir Test.MethodTested("getCellRangeByName()", bOK) 118cdf0e10cSrcweir 119cdf0e10cSrcweirExit Sub 120cdf0e10cSrcweirErrHndl: 121cdf0e10cSrcweir Test.Exception() 122cdf0e10cSrcweir bOK = false 123cdf0e10cSrcweir resume next 124cdf0e10cSrcweirEnd Sub 125cdf0e10cSrcweirFunction getCharacter( nCol as Integer) as String 126cdf0e10cSrcweir Dim Char As String 127cdf0e10cSrcweir Dim nNum As Integer 128cdf0e10cSrcweir nNum = nCol 129cdf0e10cSrcweir Char = "" 130cdf0e10cSrcweir if (nNum - 26) > 0 Then 131cdf0e10cSrcweir Char = Chr((nNum mod 26)+65) 132cdf0e10cSrcweir nNum = Int((nNum - 26)/ 26) 133cdf0e10cSrcweir end if 134cdf0e10cSrcweir Char = Chr(nNum + 65) + Char 135cdf0e10cSrcweir getCharacter = Char 136cdf0e10cSrcweirEnd Function 137cdf0e10cSrcweir</script:module> 138