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' 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' Be sure that all variables are dimensioned:
38option explicit
39
40
41
42Sub RunTest()
43
44'*************************************************************************
45' INTERFACE:
46' com.sun.star.sheet.XNamedRanges
47'*************************************************************************
48On Error Goto ErrHndl
49    Dim bOK As Boolean
50    Dim count As Integer
51    Dim outRange As New com.sun.star.table.CellAddress
52    Dim range As New com.sun.star.table.CellRangeAddress
53    Dim i As Integer
54
55    Test.StartMethod("addNewByName()")
56    bOK = true
57    outRange.Sheet = 0
58    outRange.Row = 1
59    outRange.Column = 1
60    count = oObj.Count
61    oObj.addNewByName(cIfcShortName, "T4:Y7", outRange, 0)
62    bOK = bOK AND oObj.count = count + 1
63    bOK = bOK AND oObj.hasByName(cIfcShortName)
64    Test.MethodTested("addNewByName()", bOK)
65
66    Test.StartMethod("addNewFromTitles()")
67    bOK = true
68    count = oObj.count
69
70    range.Sheet = 0
71    range.StartRow = 1
72    range.StartColumn = 2
73    range.EndRow = 3
74    range.EndColumn = 4
75
76    for i = 1 to 5
77        oDoc.Sheets(0).getCellByPosition(i, 1).String = "Col" &amp; i
78    next i
79
80    oObj.addNewFromTitles(range, com.sun.star.sheet.Border.TOP)
81
82    bOK = bOK AND (oObj.count = count + 3)
83
84    bOK = bOK AND NOT oObj.hasByName("Col1")
85    bOK = bOK AND oObj.hasByName("Col2")
86    bOK = bOK AND oObj.hasByName("Col3")
87    bOK = bOK AND oObj.hasByName("Col4")
88    bOK = bOK AND NOT oObj.hasByName("Col5")
89    Test.MethodTested("addNewFromTitles()", bOK)
90
91    Test.StartMethod("removeByName()")
92    bOK = true
93    count = oObj.Count
94    oObj.removeByName(cIfcShortName)
95    bOK = bOK AND (count = oObj.count + 1)
96    bOK = bOK AND NOT oObj.hasByName(cIfcShortName)
97    Test.MethodTested("removeByName()", bOK)
98
99    Test.StartMethod("outputList()")
100    bOK = true
101    outRange.Sheet = 0
102    outRange.Row = 5
103    outRange.Column = 5
104
105    count = oObj.count
106    for i = 4 to 5 + count
107        oDoc.Sheets(0).getCellByPosition(5, i).String = "a"
108        oDoc.Sheets(0).getCellByPosition(6, i).String = "b"
109    next i
110
111    oObj.outputList(outRange)
112
113    bOK = bOK AND oDoc.Sheets(0).getCellByPosition(5, 4).String = "a"
114    bOK = bOK AND oDoc.Sheets(0).getCellByPosition(6, 4).String = "b"
115    bOK = bOK AND oDoc.Sheets(0).getCellByPosition(5, 5 + count).String = "a"
116    bOK = bOK AND oDoc.Sheets(0).getCellByPosition(6, 5 + count).String = "b"
117
118    for i = 5 to 4 + count
119        bOK = bOK AND oDoc.Sheets(0).getCellByPosition(5, i).String &lt;&gt; "a"
120        bOK = bOK AND oDoc.Sheets(0).getCellByPosition(6, i).String &lt;&gt; "b"
121        bOK = bOK AND oObj.hasByName(oDoc.Sheets(0).getCellByPosition(5, i).String)
122    next i
123
124    Test.MethodTested("outputList()", bOK)
125
126Exit Sub
127ErrHndl:
128    Test.Exception()
129    bOK = false
130    resume next
131End Sub
132</script:module>
133