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