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_XNamedRanges" script:language="StarBasic"> 4 5 6'************************************************************************* 7' 8' Licensed to the Apache Software Foundation (ASF) under one 9' or more contributor license agreements. See the NOTICE file 10' distributed with this work for additional information 11' regarding copyright ownership. The ASF licenses this file 12' to you under the Apache License, Version 2.0 (the 13' "License"); you may not use this file except in compliance 14' with the License. You may obtain a copy of the License at 15' 16' http://www.apache.org/licenses/LICENSE-2.0 17' 18' Unless required by applicable law or agreed to in writing, 19' software distributed under the License is distributed on an 20' "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 21' KIND, either express or implied. See the License for the 22' specific language governing permissions and limitations 23' under the License. 24' 25'************************************************************************* 26 27 28 29 30 31' Be sure that all variables are dimensioned: 32option explicit 33 34 35 36Sub RunTest() 37 38'************************************************************************* 39' INTERFACE: 40' com.sun.star.sheet.XNamedRanges 41'************************************************************************* 42On Error Goto ErrHndl 43 Dim bOK As Boolean 44 Dim count As Integer 45 Dim outRange As New com.sun.star.table.CellAddress 46 Dim range As New com.sun.star.table.CellRangeAddress 47 Dim i As Integer 48 49 Test.StartMethod("addNewByName()") 50 bOK = true 51 outRange.Sheet = 0 52 outRange.Row = 1 53 outRange.Column = 1 54 count = oObj.Count 55 oObj.addNewByName(cIfcShortName, "T4:Y7", outRange, 0) 56 bOK = bOK AND oObj.count = count + 1 57 bOK = bOK AND oObj.hasByName(cIfcShortName) 58 Test.MethodTested("addNewByName()", bOK) 59 60 Test.StartMethod("addNewFromTitles()") 61 bOK = true 62 count = oObj.count 63 64 range.Sheet = 0 65 range.StartRow = 1 66 range.StartColumn = 2 67 range.EndRow = 3 68 range.EndColumn = 4 69 70 for i = 1 to 5 71 oDoc.Sheets(0).getCellByPosition(i, 1).String = "Col" & i 72 next i 73 74 oObj.addNewFromTitles(range, com.sun.star.sheet.Border.TOP) 75 76 bOK = bOK AND (oObj.count = count + 3) 77 78 bOK = bOK AND NOT oObj.hasByName("Col1") 79 bOK = bOK AND oObj.hasByName("Col2") 80 bOK = bOK AND oObj.hasByName("Col3") 81 bOK = bOK AND oObj.hasByName("Col4") 82 bOK = bOK AND NOT oObj.hasByName("Col5") 83 Test.MethodTested("addNewFromTitles()", bOK) 84 85 Test.StartMethod("removeByName()") 86 bOK = true 87 count = oObj.Count 88 oObj.removeByName(cIfcShortName) 89 bOK = bOK AND (count = oObj.count + 1) 90 bOK = bOK AND NOT oObj.hasByName(cIfcShortName) 91 Test.MethodTested("removeByName()", bOK) 92 93 Test.StartMethod("outputList()") 94 bOK = true 95 outRange.Sheet = 0 96 outRange.Row = 5 97 outRange.Column = 5 98 99 count = oObj.count 100 for i = 4 to 5 + count 101 oDoc.Sheets(0).getCellByPosition(5, i).String = "a" 102 oDoc.Sheets(0).getCellByPosition(6, i).String = "b" 103 next i 104 105 oObj.outputList(outRange) 106 107 bOK = bOK AND oDoc.Sheets(0).getCellByPosition(5, 4).String = "a" 108 bOK = bOK AND oDoc.Sheets(0).getCellByPosition(6, 4).String = "b" 109 bOK = bOK AND oDoc.Sheets(0).getCellByPosition(5, 5 + count).String = "a" 110 bOK = bOK AND oDoc.Sheets(0).getCellByPosition(6, 5 + count).String = "b" 111 112 for i = 5 to 4 + count 113 bOK = bOK AND oDoc.Sheets(0).getCellByPosition(5, i).String <> "a" 114 bOK = bOK AND oDoc.Sheets(0).getCellByPosition(6, i).String <> "b" 115 bOK = bOK AND oObj.hasByName(oDoc.Sheets(0).getCellByPosition(5, i).String) 116 next i 117 118 Test.MethodTested("outputList()", bOK) 119 120Exit Sub 121ErrHndl: 122 Test.Exception() 123 bOK = false 124 resume next 125End Sub 126</script:module> 127