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="sc_ScDataPilotTableObj" 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' REQUIRED VARIABLES for interface/service tests:
36
37' Requiered for com.sun.star.container.XNamed
38Global cNameToSet As String ' "fixed" if name is fixed
39
40' Required for com.sun.star.sheet.XDataPilotTable
41Global oOutputRange As Variant
42
43
44Sub CreateObj()
45
46'*************************************************************************
47' COMPONENT:
48' sc.ScDataPilotTableObj
49'*************************************************************************
50On Error Goto ErrHndl
51    Dim oSheet As Object
52    Dim i, j As Integer
53    Dim oDataPilotTables As Object
54    Dim oDataPilotDescriptor As Object
55    Dim oFilterDescriptor As Object
56    Dim oDataPilotField As Object
57
58    oDoc = utils.createDocument("scalc", cObjectName)
59    oSheet = oDoc.Sheets.getByIndex(0)
60
61    for i = 1 to 5
62    	oSheet.getCellByPosition(0, i).String = "Row" &amp; i
63    	oSheet.getCellByPosition(i, 0).String = "Col" &amp; i
64    next i
65
66    for i = 1 to 5
67        for j = 1 to 5
68            oSheet.getCellByPosition(i, j).Value = 2.5 * j + i
69        next j
70    next i
71
72    Dim sCellRangeAddress As New com.sun.star.table.CellRangeAddress
73    sCellRangeAddress.Sheet = 0
74    sCellRangeAddress.StartColumn = 1
75    sCellRangeAddress.StartRow = 0
76    sCellRangeAddress.EndColumn = 1
77    sCellRangeAddress.EndRow = 5
78
79    Dim sCellAddress As New com.sun.star.table.CellAddress
80    sCellAddress.Sheet = 0
81    sCellAddress.Column = 7
82    sCellAddress.Row = 8
83
84    Dim FilterFields(1) As New com.sun.star.sheet.TableFilterField
85    FilterFields(0).Connection = com.sun.star.sheet.FilterConnection.AND
86    FilterFields(0).Field = 1
87    FilterFields(0).isNumeric = true
88    FilterFields(0).StringValue = "4"
89    FilterFields(0).Operator = com.sun.star.sheet.FilterOperator.GREATER
90
91    FilterFields(1).Connection = com.sun.star.sheet.FilterConnection.AND
92    FilterFields(1).Field = 1
93    FilterFields(1).isNumeric = true
94    FilterFields(1).StringValue = "12"
95    FilterFields(1).Operator = com.sun.star.sheet.FilterOperator.LESS_EQUAL
96
97    oDataPilotTables = oSheet.getDataPilotTables
98    oDataPilotDescriptor = oDataPilotTables.createDataPilotDescriptor()
99    oDataPilotDescriptor.setSourceRange(sCellRangeAddress)
100    oFilterDescriptor = oDataPilotDescriptor.getFilterDescriptor()
101    oFilterDescriptor.setFilterFields(FilterFields())
102
103    oDataPilotField = oDataPilotDescriptor.getDataPilotFields().getByIndex(0)
104    oDataPilotField.Function = com.sun.star.sheet.GeneralFunction.SUM
105    oDataPilotField.Orientation = com.sun.star.sheet.DataPilotFieldOrientation.DATA
106
107    oDataPilotTables.insertNewByName(cObjectName, sCellAddress, oDataPilotDescriptor)
108
109    oObj = oDataPilotTables(0)
110    oOutputRange = sCellAddress
111
112Exit Sub
113ErrHndl:
114    Test.Exception()
115End Sub
116
117</script:module>
118