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