'************************************************************************* ' ' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ' ' Copyright 2000, 2010 Oracle and/or its affiliates. ' ' OpenOffice.org - a multi-platform office productivity suite ' ' This file is part of OpenOffice.org. ' ' OpenOffice.org is free software: you can redistribute it and/or modify ' it under the terms of the GNU Lesser General Public License version 3 ' only, as published by the Free Software Foundation. ' ' OpenOffice.org is distributed in the hope that it will be useful, ' but WITHOUT ANY WARRANTY; without even the implied warranty of ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ' GNU Lesser General Public License version 3 for more details ' (a copy is included in the LICENSE file that accompanied this code). ' ' You should have received a copy of the GNU Lesser General Public License ' version 3 along with OpenOffice.org. If not, see ' ' for a copy of the LGPLv3 License. ' '************************************************************************* '************************************************************************* ' REQUIRED VARIABLES for interface/service tests: ' com.sun.star.task.XJob: Global vXJobArgs(0 to 3) as Variant ' com.sun.star.text.MailMerge Global cMailMerge_DocumentURL as String Dim cDataSourceName as String Dim cDataCommand as String Dim oXResultSet as Variant ' Be sure that all variables are dimensioned: option explicit Sub CreateObj() '************************************************************************* ' COMPONENT: ' com.sun.star.sw.SwXMailMerge '************************************************************************* On Error Goto ErrHndl Dim vXJobArg0(0 to 7) as new com.sun.star.beans.NamedValue Dim vXJobArg1(0 to 6) as new com.sun.star.beans.NamedValue Dim vXJobArg2(0 to 9) as new com.sun.star.beans.NamedValue Dim vXJobArg3(0) as new com.sun.star.beans.NamedValue Dim cTestDoc as String Dim cOutputURL as String Dim oXConnection as Variant Dim myBookMarks as Variant oObj = createUnoService("com.sun.star.text.MailMerge") cTestDoc = utils.Path2URL(cTestDocsDir + "/" + "MailMerge.sxw") cMailMerge_DocumentURL = cTestDoc cOutputURL = ConvertToURL(utils.getUserPath()) cDataSourceName = "Bibliography" cDataCommand = "biblio" oXResultSet = getXResultSet() oXConnection = oXResultSet.ActiveConnection ' create arguments for XJob: myBookMarks = getMyBookMarks() oObj.DataSourceName = cDataSourceName oObj.Command = cDataCommand oObj.CommandType = com.sun.star.sdb.CommandType.TABLE oObj.OutputType = com.sun.star.text.MailMergeType.FILE oObj.DocumentURL = cTestDoc oObj.OutputURL = cOutputURL oObj.FileNamePrefix = "Author" oObj.FileNameFromColumn = TRUE oObj.Selection = DimArray() ' use a simple DataBase with simple Table vXJobArg0(0).Name = "DataSourceName" : vXJobArg0(0).Value = cDataSourceName vXJobArg0(1).Name = "Command" : vXJobArg0(1).Value = cDataCommand vXJobArg0(2).Name = "CommandType" : vXJobArg0(2).Value = com.sun.star.sdb.CommandType.TABLE vXJobArg0(3).Name = "OutputType" : vXJobArg0(3).Value = com.sun.star.text.MailMergeType.FILE vXJobArg0(4).Name = "DocumentURL" : vXJobArg0(4).Value = cTestDoc vXJobArg0(5).Name = "OutputURL" : vXJobArg0(5).Value = cOutputURL vXJobArg0(6).Name = "FileNamePrefix" : vXJobArg0(6).Value = "Identifier" vXJobArg0(7).Name = "FileNameFromColumn" : vXJobArg0(7).Value = true ' use a simple DataBase with simple Table and write to printer vXJobArg1(0).Name = "DataSourceName" : vXJobArg1(0).Value = cDataSourceName vXJobArg1(1).Name = "Command" : vXJobArg1(1).Value = cDataCommand vXJobArg1(2).Name = "CommandType" : vXJobArg1(2).Value = com.sun.star.sdb.CommandType.TABLE vXJobArg1(3).Name = "OutputType" : vXJobArg1(3).Value = com.sun.star.text.MailMergeType.PRINTER vXJobArg1(4).Name = "FileNamePrefix" : vXJobArg1(4).Value = "Author" vXJobArg1(5).Name = "FileNameFromColumn" : vXJobArg1(5).Value = true vXJobArg1(6).Name = "DocumentURL" : vXJobArg1(6).Value = cTestDoc ' use a XConnection vXJobArg2(0).Name = "ActiveConnection" : vXJobArg2(0).Value = oXConnection vXJobArg2(1).Name = "DataSourceName" : vXJobArg2(1).Value = cDataSourceName vXJobArg2(2).Name = "Command" : vXJobArg2(2).Value = cDataCommand vXJobArg2(3).Name = "CommandType" : vXJobArg2(3).Value = com.sun.star.sdb.CommandType.TABLE vXJobArg2(4).Name = "OutputType" : vXJobArg2(4).Value = com.sun.star.text.MailMergeType.FILE vXJobArg2(5).Name = "ResultSet" : vXJobArg2(5).Value = oXResultSet vXJobArg2(6).Name = "OutputURL" : vXJobArg2(6).Value = cOutputURL vXJobArg2(7).Name = "FileNamePrefix" : vXJobArg2(7).Value = "Identifier" vXJobArg2(8).Name = "FileNameFromColumn" : vXJobArg2(8).Value = true vXJobArg2(9).Name = "Selection" : vXJobArg2(9).Value = myBookMarks() vXJobArgs(0) = vXJobArg0() vXJobArgs(1) = vXJobArg1() vXJobArgs(2) = vXJobArg2() vXJobArgs(3) = DimArray() out.log("com.sun.star.text.MailMerge created.") Exit Sub ErrHndl: Test.Exception() End Sub Sub XMailMergeEvent() oObj.execute(vXJobArgs(2)) end sub Function getXResultSet() as Variant Dim oRowSet as Object oRowSet = createUnoService("com.sun.star.sdb.RowSet") oRowSet.DataSourceName = cDataSourceName oRowSet.Command = cDataCommand oRowSet.CommandType = com.sun.star.sdb.CommandType.TABLE oRowSet.execute() wait(200) ' oRowSet.getFirst() getXResultSet() = oRowSet end Function Function getMyBookMarks() as Variant Dim BookMarks(1) as Variant oXResultSet.first() BookMarks(0) = oXResultSet.getBookmark() oXResultSet.next() BookMarks(1) = oXResultSet.getBookmark() getMyBookMarks() = BookMarks() end Function