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="sch_ChXDiagram" 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 41Dim nCol As Integer 42Dim nRow As Integer 43 44' REQUIRED VARIABLES for interface/service tests: 45Global oLineDiagram As Object 46Global oStackDiagram As Object 47Global oStockDiagram As Object 48Global oBarDiagram As Object 49Global nGlobalBarDiagram As Long 50 51' For drawing.XShapeDescriptor 52Global cShapeType As String 53 54 55Sub CreateObj() 56 57'************************************************************************* 58' COMPONENT: 59' sch.ChXDiagram 60'************************************************************************* 61On Error Goto ErrHndl 62 Dim oCharts As Object 63 Dim oChart As Object 64 Dim cType(4) As String 65 Dim mRangeAddress(0) As New com.sun.star.table.CellRangeAddress 66 Dim aRect As New com.sun.star.awt.Rectangle 67 Dim n As Integer 68 69 oDoc = utils.createDocument("scalc", cObjectName) 70 71 cType(0) = "StockDiagram" 72 cType(1) = "BarDiagram" 73 cType(2) = "XYDiagram" 74 cType(3) = "StackableDiagram" 75 cType(4) = "LineDiagram" 76 77 nCol = 5 78 nRow = 6 79 FillCells() 80 81 aRect.Width = 5000 82 aRect.Height = 5000 83 mRangeAddress(0).Sheet = 0 84 mRangeAddress(0).StartColumn = 0 85 mRangeAddress(0).StartRow = 0 86 mRangeAddress(0).EndColumn = nCol 87 mRangeAddress(0).EndRow = nRow 88 89 for n = 0 to 4 90 aRect.X = 500 * n 91 aRect.Y = 3000 * n 92 oCharts = oDoc.Sheets(0).Charts 93 oCharts.addNewByName(cObjectName + cType(n) + n, aRect, mRangeAddress(), true, true) 94 oChart = oCharts.getByName(cObjectName + cType(n) + n).EmbeddedObject 95 oChart.Diagram = oChart.createInstance("com.sun.star.chart." + cType(n)) 96 next n 97 98 oStockDiagram = oCharts.getByName(cObjectName + cType(0) + 0).EmbeddedObject.Diagram 99 oBarDiagram = oCharts.getByName(cObjectName + cType(1) + 1).EmbeddedObject.Diagram 100 oLineDiagram = oCharts.getByName(cObjectName + cType(2) + 2).EmbeddedObject.Diagram 101 oStackDiagram = oCharts.getByName(cObjectName + cType(3) + 3).EmbeddedObject.Diagram 102 oObj = oCharts.getByName(cObjectName + cType(4) + 4).EmbeddedObject.Diagram 103 104 nGlobalBarDiagram = 4 105 106 ' For drawing.XShapeDescriptor 107 cShapeType = "com.sun.star.chart.Diagram" 108 109Exit Sub 110ErrHndl: 111 Test.Exception() 112End Sub 113 114Sub FillCells() 115 Dim oCell As Object 116 Dim oRange As Object 117 Dim n1 As Integer 118 Dim n2 As Integer 119 Dim oFormats As Variant 120 Dim nFormat As Integer 121 Dim nKey As Integer 122 Dim aLanguage As New com.sun.star.lang.Locale 123 124 oRange = oDoc.Sheets(0).getCellRangeByPosition(0, 0, nCol, nRow) 125 126 for n1 = 1 to nCol - 1 127 For n2 = 1 To nRow - 1 128 oRange.getCellByPosition(n1, n2).Value = n2 * (n1 + 1) 129 Next n2 130 next n1 131 132 for n1 = 1 to nCol - 1 133 oRange.getCellByPosition(n1, 0).String = "Col " + n1 134 next n1 135 for n2 = 1 to nRow - 1 136 oRange.getCellByPosition(0, n2).String = "Row " + n2 137 next n2 138 139 oFormats = oDoc.NumberFormats 140 nFormat = com.sun.star.util.NumberFormat.CURRENCY 141 nKey = oFormats.getStandardFormat(nFormat, aLanguage) 142 oRange.NumberFormat = nKey 143End Sub 144</script:module> 145