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="container_XNameReplace" 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' This Interface/Service test depends on the following GLOBAL variables, 36' which must be specified in the object creation: 37 38' Global cNameToReplace As String 'name of instance to be replased 39' Global oReplaceInstance As Variant 'instance, that will be inserted 40' instead old one 41 42'************************************************************************* 43 44Sub RunTest() 45 46'************************************************************************* 47' INTERFACE: 48' com.sun.star.container.XNameReplace 49'************************************************************************* 50On Error Goto ErrHndl 51 Dim bOK As Boolean 52 Dim oOldObject As Object 53 Dim cOldObjName As String 54 Dim oNewControl As Object 55 Dim cNewObjName As String 56 Dim NewAddress As Object 57 Dim InstAddress As Object 58 Dim cReplInstName As String 59 60 Test.StartMethod("replaceByName()") 61 bOK = true 62 63 if (cObjectName = "sc.ScCellRangesObj") then 64 oOldObject = oObj.getByName(cNameToReplace) 65 InstAddress = oReplaceInstance.getRangeAddress 66 67 oObj.replaceByName(cNameToReplace, oReplaceInstance) 68 69 oNewControl = oObj.getByName(cNameToReplace) 70 NewAddress = oNewControl.getRangeAddress 71 72 bOK = bOK AND NewAddress.Sheet = InstAddress.Sheet 73 bOK = bOK AND NewAddress.StartColumn = InstAddress.StartColumn 74 bOK = bOK AND NewAddress.EndColumn = InstAddress.EndColumn 75 bOK = bOK AND NewAddress.StartRow = InstAddress.StartRow 76 bOK = bOK AND NewAddress.EndRow = InstAddress.EndRow 77 78 elseif typename(oReplaceInstance) = "String" then 79 Dim oNewObj as Variant 80 Dim oOldObj as Variant 81 oOldObj = oObj.getByName(cNameToReplace) 82 oObj.replaceByName(cNameToReplace, oReplaceInstance) 83 oNewObj = oObj.getByName(cNameToReplace) 84 bOK = bOK and not PropertyTester.equals(oOldObj, oNewObj) 85 else 86 oOldObject = oObj.getByName(cNameToReplace) 87 cReplInstName = oReplaceInstance.Name 88 Out.Log("ReplaceInstance.name = '" & cReplInstName & "'") 89 cOldObjName = oOldObject.Name 90 Out.Log("OldObject.name = '" & cOldObjName & "'") 91 92 oObj.replaceByName(cNameToReplace, oReplaceInstance) 93 oNewControl = oObj.getByName(cNameToReplace) 94 95 cReplInstName = oReplaceInstance.Name 96 Out.Log("ReplaceInstance.name = '" & cReplInstName & "'") 97 cNewObjName = oNewControl.Name 98 Out.Log("NewObject.name = '" & cNewObjName & "'") 99 100 bOK = bOK AND (oReplaceInstance.Name = cNameToReplace) 101 end if 102 103 Test.MethodTested("replaceByName()", bOK) 104 105Exit Sub 106ErrHndl: 107 Test.Exception() 108 bOK = false 109 resume next 110End Sub 111</script:module> 112