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' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7' 8' Copyright 2000, 2010 Oracle and/or its affiliates. 9' 10' OpenOffice.org - a multi-platform office productivity suite 11' 12' This file is part of OpenOffice.org. 13' 14' OpenOffice.org is free software: you can redistribute it and/or modify 15' it under the terms of the GNU Lesser General Public License version 3 16' only, as published by the Free Software Foundation. 17' 18' OpenOffice.org is distributed in the hope that it will be useful, 19' but WITHOUT ANY WARRANTY; without even the implied warranty of 20' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21' GNU Lesser General Public License version 3 for more details 22' (a copy is included in the LICENSE file that accompanied this code). 23' 24' You should have received a copy of the GNU Lesser General Public License 25' version 3 along with OpenOffice.org. If not, see 26' <http://www.openoffice.org/license.html> 27' for a copy of the LGPLv3 License. 28' 29'************************************************************************* 30***** 31'************************************************************************* 32 33' REQUIRED VARIABLES for interface/service tests: 34 35' com.sun.star.task.XJob: 36Global vXJobArgs(0 to 3) as Variant 37 38' com.sun.star.text.MailMerge 39Global cMailMerge_DocumentURL as String 40 41Dim cDataSourceName as String 42Dim cDataCommand as String 43Dim oXResultSet as Variant 44 45' Be sure that all variables are dimensioned: 46option explicit 47 48Sub CreateObj() 49 50'************************************************************************* 51' COMPONENT: 52' com.sun.star.sw.SwXMailMerge 53'************************************************************************* 54On Error Goto ErrHndl 55 56 Dim vXJobArg0(0 to 7) as new com.sun.star.beans.NamedValue 57 Dim vXJobArg1(0 to 6) as new com.sun.star.beans.NamedValue 58 Dim vXJobArg2(0 to 9) as new com.sun.star.beans.NamedValue 59 Dim vXJobArg3(0) as new com.sun.star.beans.NamedValue 60 Dim cTestDoc as String 61 Dim cOutputURL as String 62 Dim oXConnection as Variant 63 Dim myBookMarks as Variant 64 65 oObj = createUnoService("com.sun.star.text.MailMerge") 66 67 cTestDoc = utils.Path2URL(cTestDocsDir + "/" + "MailMerge.sxw") 68 cMailMerge_DocumentURL = cTestDoc 69 cOutputURL = ConvertToURL(utils.getUserPath()) 70 cDataSourceName = "Bibliography" 71 cDataCommand = "biblio" 72 oXResultSet = getXResultSet() 73 oXConnection = oXResultSet.ActiveConnection 74 75 ' create arguments for XJob: 76 myBookMarks = getMyBookMarks() 77 78 oObj.DataSourceName = cDataSourceName 79 oObj.Command = cDataCommand 80 oObj.CommandType = com.sun.star.sdb.CommandType.TABLE 81 oObj.OutputType = com.sun.star.text.MailMergeType.FILE 82 oObj.DocumentURL = cTestDoc 83 oObj.OutputURL = cOutputURL 84 oObj.FileNamePrefix = "Author" 85 oObj.FileNameFromColumn = TRUE 86 oObj.Selection = DimArray() 87 88 ' use a simple DataBase with simple Table 89 vXJobArg0(0).Name = "DataSourceName" : vXJobArg0(0).Value = cDataSourceName 90 vXJobArg0(1).Name = "Command" : vXJobArg0(1).Value = cDataCommand 91 vXJobArg0(2).Name = "CommandType" : vXJobArg0(2).Value = com.sun.star.sdb.CommandType.TABLE 92 vXJobArg0(3).Name = "OutputType" : vXJobArg0(3).Value = com.sun.star.text.MailMergeType.FILE 93 vXJobArg0(4).Name = "DocumentURL" : vXJobArg0(4).Value = cTestDoc 94 vXJobArg0(5).Name = "OutputURL" : vXJobArg0(5).Value = cOutputURL 95 vXJobArg0(6).Name = "FileNamePrefix" : vXJobArg0(6).Value = "Identifier" 96 vXJobArg0(7).Name = "FileNameFromColumn" : vXJobArg0(7).Value = true 97 98 ' use a simple DataBase with simple Table and write to printer 99 vXJobArg1(0).Name = "DataSourceName" : vXJobArg1(0).Value = cDataSourceName 100 vXJobArg1(1).Name = "Command" : vXJobArg1(1).Value = cDataCommand 101 vXJobArg1(2).Name = "CommandType" : vXJobArg1(2).Value = com.sun.star.sdb.CommandType.TABLE 102 vXJobArg1(3).Name = "OutputType" : vXJobArg1(3).Value = com.sun.star.text.MailMergeType.PRINTER 103 vXJobArg1(4).Name = "FileNamePrefix" : vXJobArg1(4).Value = "Author" 104 vXJobArg1(5).Name = "FileNameFromColumn" : vXJobArg1(5).Value = true 105 vXJobArg1(6).Name = "DocumentURL" : vXJobArg1(6).Value = cTestDoc 106 107 ' use a XConnection 108 vXJobArg2(0).Name = "ActiveConnection" : vXJobArg2(0).Value = oXConnection 109 vXJobArg2(1).Name = "DataSourceName" : vXJobArg2(1).Value = cDataSourceName 110 vXJobArg2(2).Name = "Command" : vXJobArg2(2).Value = cDataCommand 111 vXJobArg2(3).Name = "CommandType" : vXJobArg2(3).Value = com.sun.star.sdb.CommandType.TABLE 112 vXJobArg2(4).Name = "OutputType" : vXJobArg2(4).Value = com.sun.star.text.MailMergeType.FILE 113 vXJobArg2(5).Name = "ResultSet" : vXJobArg2(5).Value = oXResultSet 114 vXJobArg2(6).Name = "OutputURL" : vXJobArg2(6).Value = cOutputURL 115 vXJobArg2(7).Name = "FileNamePrefix" : vXJobArg2(7).Value = "Identifier" 116 vXJobArg2(8).Name = "FileNameFromColumn" : vXJobArg2(8).Value = true 117 vXJobArg2(9).Name = "Selection" : vXJobArg2(9).Value = myBookMarks() 118 119 vXJobArgs(0) = vXJobArg0() 120 vXJobArgs(1) = vXJobArg1() 121 vXJobArgs(2) = vXJobArg2() 122 vXJobArgs(3) = DimArray() 123 124 out.log("com.sun.star.text.MailMerge created.") 125 126Exit Sub 127ErrHndl: 128 Test.Exception() 129End Sub 130 131Sub XMailMergeEvent() 132 oObj.execute(vXJobArgs(2)) 133end sub 134 135Function getXResultSet() as Variant 136 Dim oRowSet as Object 137 oRowSet = createUnoService("com.sun.star.sdb.RowSet") 138 oRowSet.DataSourceName = cDataSourceName 139 oRowSet.Command = cDataCommand 140 oRowSet.CommandType = com.sun.star.sdb.CommandType.TABLE 141 oRowSet.execute() 142 wait(200) 143' oRowSet.getFirst() 144 getXResultSet() = oRowSet 145end Function 146 147Function getMyBookMarks() as Variant 148 Dim BookMarks(1) as Variant 149 oXResultSet.first() 150 BookMarks(0) = oXResultSet.getBookmark() 151 oXResultSet.next() 152 BookMarks(1) = oXResultSet.getBookmark() 153 getMyBookMarks() = BookMarks() 154end Function 155 156</script:module> 157