1<?xml version="1.0" encoding="UTF-8"?> 2<script:module xmlns:script="http://openoffice.org/2000/script" script:name="sw_SwXMailMerge" script:language="StarBasic"> 3 4'************************************************************************* 5' 6' Licensed to the Apache Software Foundation (ASF) under one 7' or more contributor license agreements. See the NOTICE file 8' distributed with this work for additional information 9' regarding copyright ownership. The ASF licenses this file 10' to you under the Apache License, Version 2.0 (the 11' "License"); you may not use this file except in compliance 12' with the License. You may obtain a copy of the License at 13' 14' http://www.apache.org/licenses/LICENSE-2.0 15' 16' Unless required by applicable law or agreed to in writing, 17' software distributed under the License is distributed on an 18' "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 19' KIND, either express or implied. See the License for the 20' specific language governing permissions and limitations 21' under the License. 22' 23'************************************************************************* 24 25 26 27' REQUIRED VARIABLES for interface/service tests: 28 29' com.sun.star.task.XJob: 30Global vXJobArgs(0 to 3) as Variant 31 32' com.sun.star.text.MailMerge 33Global cMailMerge_DocumentURL as String 34 35Dim cDataSourceName as String 36Dim cDataCommand as String 37Dim oXResultSet as Variant 38 39' Be sure that all variables are dimensioned: 40option explicit 41 42Sub CreateObj() 43 44'************************************************************************* 45' COMPONENT: 46' com.sun.star.sw.SwXMailMerge 47'************************************************************************* 48On Error Goto ErrHndl 49 50 Dim vXJobArg0(0 to 7) as new com.sun.star.beans.NamedValue 51 Dim vXJobArg1(0 to 6) as new com.sun.star.beans.NamedValue 52 Dim vXJobArg2(0 to 9) as new com.sun.star.beans.NamedValue 53 Dim vXJobArg3(0) as new com.sun.star.beans.NamedValue 54 Dim cTestDoc as String 55 Dim cOutputURL as String 56 Dim oXConnection as Variant 57 Dim myBookMarks as Variant 58 59 oObj = createUnoService("com.sun.star.text.MailMerge") 60 61 cTestDoc = utils.Path2URL(cTestDocsDir + "/" + "MailMerge.sxw") 62 cMailMerge_DocumentURL = cTestDoc 63 cOutputURL = ConvertToURL(utils.getUserPath()) 64 cDataSourceName = "Bibliography" 65 cDataCommand = "biblio" 66 oXResultSet = getXResultSet() 67 oXConnection = oXResultSet.ActiveConnection 68 69 ' create arguments for XJob: 70 myBookMarks = getMyBookMarks() 71 72 oObj.DataSourceName = cDataSourceName 73 oObj.Command = cDataCommand 74 oObj.CommandType = com.sun.star.sdb.CommandType.TABLE 75 oObj.OutputType = com.sun.star.text.MailMergeType.FILE 76 oObj.DocumentURL = cTestDoc 77 oObj.OutputURL = cOutputURL 78 oObj.FileNamePrefix = "Author" 79 oObj.FileNameFromColumn = TRUE 80 oObj.Selection = DimArray() 81 82 ' use a simple DataBase with simple Table 83 vXJobArg0(0).Name = "DataSourceName" : vXJobArg0(0).Value = cDataSourceName 84 vXJobArg0(1).Name = "Command" : vXJobArg0(1).Value = cDataCommand 85 vXJobArg0(2).Name = "CommandType" : vXJobArg0(2).Value = com.sun.star.sdb.CommandType.TABLE 86 vXJobArg0(3).Name = "OutputType" : vXJobArg0(3).Value = com.sun.star.text.MailMergeType.FILE 87 vXJobArg0(4).Name = "DocumentURL" : vXJobArg0(4).Value = cTestDoc 88 vXJobArg0(5).Name = "OutputURL" : vXJobArg0(5).Value = cOutputURL 89 vXJobArg0(6).Name = "FileNamePrefix" : vXJobArg0(6).Value = "Identifier" 90 vXJobArg0(7).Name = "FileNameFromColumn" : vXJobArg0(7).Value = true 91 92 ' use a simple DataBase with simple Table and write to printer 93 vXJobArg1(0).Name = "DataSourceName" : vXJobArg1(0).Value = cDataSourceName 94 vXJobArg1(1).Name = "Command" : vXJobArg1(1).Value = cDataCommand 95 vXJobArg1(2).Name = "CommandType" : vXJobArg1(2).Value = com.sun.star.sdb.CommandType.TABLE 96 vXJobArg1(3).Name = "OutputType" : vXJobArg1(3).Value = com.sun.star.text.MailMergeType.PRINTER 97 vXJobArg1(4).Name = "FileNamePrefix" : vXJobArg1(4).Value = "Author" 98 vXJobArg1(5).Name = "FileNameFromColumn" : vXJobArg1(5).Value = true 99 vXJobArg1(6).Name = "DocumentURL" : vXJobArg1(6).Value = cTestDoc 100 101 ' use a XConnection 102 vXJobArg2(0).Name = "ActiveConnection" : vXJobArg2(0).Value = oXConnection 103 vXJobArg2(1).Name = "DataSourceName" : vXJobArg2(1).Value = cDataSourceName 104 vXJobArg2(2).Name = "Command" : vXJobArg2(2).Value = cDataCommand 105 vXJobArg2(3).Name = "CommandType" : vXJobArg2(3).Value = com.sun.star.sdb.CommandType.TABLE 106 vXJobArg2(4).Name = "OutputType" : vXJobArg2(4).Value = com.sun.star.text.MailMergeType.FILE 107 vXJobArg2(5).Name = "ResultSet" : vXJobArg2(5).Value = oXResultSet 108 vXJobArg2(6).Name = "OutputURL" : vXJobArg2(6).Value = cOutputURL 109 vXJobArg2(7).Name = "FileNamePrefix" : vXJobArg2(7).Value = "Identifier" 110 vXJobArg2(8).Name = "FileNameFromColumn" : vXJobArg2(8).Value = true 111 vXJobArg2(9).Name = "Selection" : vXJobArg2(9).Value = myBookMarks() 112 113 vXJobArgs(0) = vXJobArg0() 114 vXJobArgs(1) = vXJobArg1() 115 vXJobArgs(2) = vXJobArg2() 116 vXJobArgs(3) = DimArray() 117 118 out.log("com.sun.star.text.MailMerge created.") 119 120Exit Sub 121ErrHndl: 122 Test.Exception() 123End Sub 124 125Sub XMailMergeEvent() 126 oObj.execute(vXJobArgs(2)) 127end sub 128 129Function getXResultSet() as Variant 130 Dim oRowSet as Object 131 oRowSet = createUnoService("com.sun.star.sdb.RowSet") 132 oRowSet.DataSourceName = cDataSourceName 133 oRowSet.Command = cDataCommand 134 oRowSet.CommandType = com.sun.star.sdb.CommandType.TABLE 135 oRowSet.execute() 136 wait(200) 137' oRowSet.getFirst() 138 getXResultSet() = oRowSet 139end Function 140 141Function getMyBookMarks() as Variant 142 Dim BookMarks(1) as Variant 143 oXResultSet.first() 144 BookMarks(0) = oXResultSet.getBookmark() 145 oXResultSet.next() 146 BookMarks(1) = oXResultSet.getBookmark() 147 getMyBookMarks() = BookMarks() 148end Function 149 150</script:module> 151