首页 文章

LibreOffice邮件与Java合并

提问于
浏览
0

我正在尝试从java应用程序自动使用libre office邮件合并功能 .

我试图安装libreoffice sdk但没有成功,因为它们需要的软件不再可用(例如zip工具) . 无论如何,我能够从maven存储库获取jar文件(jurtl-3.2.1.jar,ridl-3.2.1.jar,unoil-3.2.1.jar和juh-3.2.1.jar) .

有了这个jar文件,我能够重现很多这里提供的例子http://api.libreoffice.org/examples/examples.html#Java_examples

同样在LibreOffice API文档中列出了名为'MailMerge'的服务(请参阅此处http://api.libreoffice.org/docs/idl/ref/servicecom_1_1sun_1_1star_1_1text_1_1MailMerge.html

但是在这个服务类中没有一个是可用的,唯一可用的实例是MailMergeType .

我能够在我的javacode中打开一个* .odt模板文件,下一步是创建一个邮件合并服务的实例,并将* .csv数据源文件传递给邮件合并服务 .

在API文档中列出了一些可以帮助我的功能,但正如我之前所说,我无法访问此服务类,因为它根本不存在于提供的jar文件中 .

有人知道如何访问libreoffice的邮件合并服务吗?

如果您需要有关我的环境的更多信息,请询问 .

诚恳

1 回答

  • 1

    看看this code from 2004,显然你可以简单地使用Java的 Object 类 . 以下是该代码的一些代码段:

    Object mmservice = null;
    try {
        // Create an instance of the MailMerge service
        mmservice = mxMCF.createInstanceWithContext(
            "com.sun.star.text.MailMerge", mxComponentContext);
    }
    // Get the XPropertySet interface of the mmservice object
    XPropertySet oObjProps = (XPropertySet)
        UnoRuntime.queryInterface(XPropertySet.class, mmservice);
    try {
        // Set up the properties for the MailMerge command
        oObjProps.setPropertyValue("DataSourceName", mDataSourceName);
    }
    // Get XJob interface from MailMerge service and call execute on it
    XJob job = (XJob) UnoRuntime.queryInterface(XJob.class, mmservice);
    try {
        job.execute(new NamedValue[0]);
    }
    

    另见How to do a simple mail merge in OpenOffice .

    关于旧zip工具的来源,请尝试 zip.exe 来自http://www.willus.com/archive/zip64/ .

相关问题