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' REQUIRED VARIABLES for interface/service tests: 33 34' com.sun.star.task.XJob: 35Global vXJobArgs(0 to 3) as Variant 36 37' com.sun.star.text.MailMerge 38Global cMailMerge_DocumentURL as String 39 40Dim cDataSourceName as String 41Dim cDataCommand as String 42Dim oXResultSet as Variant 43 44' Be sure that all variables are dimensioned: 45option explicit 46 47Sub CreateObj() 48 49'************************************************************************* 50' COMPONENT: 51' com.sun.star.sw.SwXMailMerge 52'************************************************************************* 53On Error Goto ErrHndl 54 55 Dim vXJobArg0(0 to 7) as new com.sun.star.beans.NamedValue 56 Dim vXJobArg1(0 to 6) as new com.sun.star.beans.NamedValue 57 Dim vXJobArg2(0 to 9) as new com.sun.star.beans.NamedValue 58 Dim vXJobArg3(0) as new com.sun.star.beans.NamedValue 59 Dim cTestDoc as String 60 Dim cOutputURL as String 61 Dim oXConnection as Variant 62 Dim myBookMarks as Variant 63 64 oObj = createUnoService("com.sun.star.text.MailMerge") 65 66 cTestDoc = utils.Path2URL(cTestDocsDir + "/" + "MailMerge.sxw") 67 cMailMerge_DocumentURL = cTestDoc 68 cOutputURL = ConvertToURL(utils.getUserPath()) 69 cDataSourceName = "Bibliography" 70 cDataCommand = "biblio" 71 oXResultSet = getXResultSet() 72 oXConnection = oXResultSet.ActiveConnection 73 74 ' create arguments for XJob: 75 myBookMarks = getMyBookMarks() 76 77 oObj.DataSourceName = cDataSourceName 78 oObj.Command = cDataCommand 79 oObj.CommandType = com.sun.star.sdb.CommandType.TABLE 80 oObj.OutputType = com.sun.star.text.MailMergeType.FILE 81 oObj.DocumentURL = cTestDoc 82 oObj.OutputURL = cOutputURL 83 oObj.FileNamePrefix = "Author" 84 oObj.FileNameFromColumn = TRUE 85 oObj.Selection = DimArray() 86 87 ' use a simple DataBase with simple Table 88 vXJobArg0(0).Name = "DataSourceName" : vXJobArg0(0).Value = cDataSourceName 89 vXJobArg0(1).Name = "Command" : vXJobArg0(1).Value = cDataCommand 90 vXJobArg0(2).Name = "CommandType" : vXJobArg0(2).Value = com.sun.star.sdb.CommandType.TABLE 91 vXJobArg0(3).Name = "OutputType" : vXJobArg0(3).Value = com.sun.star.text.MailMergeType.FILE 92 vXJobArg0(4).Name = "DocumentURL" : vXJobArg0(4).Value = cTestDoc 93 vXJobArg0(5).Name = "OutputURL" : vXJobArg0(5).Value = cOutputURL 94 vXJobArg0(6).Name = "FileNamePrefix" : vXJobArg0(6).Value = "Identifier" 95 vXJobArg0(7).Name = "FileNameFromColumn" : vXJobArg0(7).Value = true 96 97 ' use a simple DataBase with simple Table and write to printer 98 vXJobArg1(0).Name = "DataSourceName" : vXJobArg1(0).Value = cDataSourceName 99 vXJobArg1(1).Name = "Command" : vXJobArg1(1).Value = cDataCommand 100 vXJobArg1(2).Name = "CommandType" : vXJobArg1(2).Value = com.sun.star.sdb.CommandType.TABLE 101 vXJobArg1(3).Name = "OutputType" : vXJobArg1(3).Value = com.sun.star.text.MailMergeType.PRINTER 102 vXJobArg1(4).Name = "FileNamePrefix" : vXJobArg1(4).Value = "Author" 103 vXJobArg1(5).Name = "FileNameFromColumn" : vXJobArg1(5).Value = true 104 vXJobArg1(6).Name = "DocumentURL" : vXJobArg1(6).Value = cTestDoc 105 106 ' use a XConnection 107 vXJobArg2(0).Name = "ActiveConnection" : vXJobArg2(0).Value = oXConnection 108 vXJobArg2(1).Name = "DataSourceName" : vXJobArg2(1).Value = cDataSourceName 109 vXJobArg2(2).Name = "Command" : vXJobArg2(2).Value = cDataCommand 110 vXJobArg2(3).Name = "CommandType" : vXJobArg2(3).Value = com.sun.star.sdb.CommandType.TABLE 111 vXJobArg2(4).Name = "OutputType" : vXJobArg2(4).Value = com.sun.star.text.MailMergeType.FILE 112 vXJobArg2(5).Name = "ResultSet" : vXJobArg2(5).Value = oXResultSet 113 vXJobArg2(6).Name = "OutputURL" : vXJobArg2(6).Value = cOutputURL 114 vXJobArg2(7).Name = "FileNamePrefix" : vXJobArg2(7).Value = "Identifier" 115 vXJobArg2(8).Name = "FileNameFromColumn" : vXJobArg2(8).Value = true 116 vXJobArg2(9).Name = "Selection" : vXJobArg2(9).Value = myBookMarks() 117 118 vXJobArgs(0) = vXJobArg0() 119 vXJobArgs(1) = vXJobArg1() 120 vXJobArgs(2) = vXJobArg2() 121 vXJobArgs(3) = DimArray() 122 123 out.log("com.sun.star.text.MailMerge created.") 124 125Exit Sub 126ErrHndl: 127 Test.Exception() 128End Sub 129 130Sub XMailMergeEvent() 131 oObj.execute(vXJobArgs(2)) 132end sub 133 134Function getXResultSet() as Variant 135 Dim oRowSet as Object 136 oRowSet = createUnoService("com.sun.star.sdb.RowSet") 137 oRowSet.DataSourceName = cDataSourceName 138 oRowSet.Command = cDataCommand 139 oRowSet.CommandType = com.sun.star.sdb.CommandType.TABLE 140 oRowSet.execute() 141 wait(200) 142' oRowSet.getFirst() 143 getXResultSet() = oRowSet 144end Function 145 146Function getMyBookMarks() as Variant 147 Dim BookMarks(1) as Variant 148 oXResultSet.first() 149 BookMarks(0) = oXResultSet.getBookmark() 150 oXResultSet.next() 151 BookMarks(1) = oXResultSet.getBookmark() 152 getMyBookMarks() = BookMarks() 153end Function 154 155</script:module> 156