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