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="sw_SwXTextTable" 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 42' REQUIRED VARIABLES for interface/service tests: 43 44' Requiered for com.sun.star.lang.XComponent 45 Global oComponentInstance As Object ' it will be disposed 46 47' Requiered for com.sun.star.chart.XChartData 48 Global oCellToChange As Object 49 50' Requiered for com.sun.star.container.XNamed 51 Global cNameToSet As String ' "fixed" if name is fixed 52 53' Requiered for com.sun.star.chart.XChartDataArray 54' Requiered for com.sun.star.text.XTextTable 55 Global nTableW As Integer 56 Global nTableH As Integer 57 58'Required for sheet.XCellRangeData 59Global newData As Variant 60 61Global oXTextContent as Object 62Global oXTextContentRange as Object 63 64 65Sub CreateObj() 66 67'************************************************************************* 68' COMPONENT: 69' sw.SwXTextTable 70'************************************************************************* 71On Error Goto ErrHndl 72 Dim oCursor As Object 73 Dim i As Integer 74 Dim oInstance As Object 75 76 oDoc = utils.createDocument("swriter", cObjectName) 77 oCursor = oDoc.Text.createTextCursor() 78 79 nTableH = 5 80 nTableW = 7 81 82 for i = 1 to 2 83 oInstance = oDoc.createInstance("com.sun.star.text.TextTable") 84 oInstance.initialize(nTableH, nTableW) 85 oInstance.Name = "Table" + i 86 ' insert created Table 87 oDoc.Text.insertTextContent(oCursor, oInstance, false) 88 if (i = 1) then oComponentInstance = oInstance 89 next i 90 91 oObj = oInstance 92 oCellToChange = oObj.getCellByPosition(3, 4) 93 cNameToSet = "NewTableName" 94 95 'Required for XCellRangeData 96 newData() = Array(_ 97 Array(2.5, 5.0, 2.5, 5.0, 3.0, 2.0, 1.0),_ 98 Array(4.0, 9.0, 2.5, 5.0, 4.0, 1.0, 2.0),_ 99 Array(2.5, 5.0, 2.5, 5.0, 3.0, 2.0, 1.0),_ 100 Array(2.5, 5.0, 2.5, 5.0, 7.0, 7.0, 8.0),_ 101 Array(4.0, 9.0, 2.5, 5.0, 4.0, 3.0, 2.0)) 102 103 oXTextContent = oDoc.createInstance("com.sun.star.text.TextTable") 104 oXTextContentRange = oDoc.Text.createTextCursor() 105 106Exit Sub 107ErrHndl: 108 Test.Exception() 109End Sub 110 111Function modifyDescriptor(descr As Variant) As Variant 112On Error Goto ErrHndl 113 Dim i As Integer, oCell As Object 114 115 for i = 0 to nTableW - 1 116 oCell = oObj.getCellByPosition(i, 0) 117 oCell.String = "" + (nTableW - i) 118 next i 119 120 for i = 0 to ubound(descr) 121 if descr(i).Name = "SortAscending" then descr(i).Value = true 122 if descr(i).Name = "SortColumns" then descr(i).Value = true 123 next i 124 125 modifyDescriptor() = descr 126Exit Function 127ErrHndl: 128 Out.Log("Exception in SwXTextTable.modifyDescriptor() :") 129 Test.Exception() 130end Function 131 132Function checkSort() As Boolean 133On Error Goto ErrHndl 134 Dim i As Integer, oCell As Object 135 Dim bOK As Boolean 136 137 bOK = true 138 for i = 0 to nTableW - 1 139 oCell = oObj.getCellByPosition(i, 0) 140 bOK = bOK AND oCell.String = "" + (i + 1) 141 next i 142 143 checkSort() = bOK 144Exit Function 145ErrHndl: 146 Out.Log("Exception in SwXTextTable.checkSort() :") 147 Test.Exception() 148end Function 149</script:module> 150