【问题标题】:LibreOffice Mail Merge with JavaLibreOffice 邮件与 Java 合并
【发布时间】:2015-11-02 13:38:44
【问题描述】:

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

我尝试安装 libreoffice sdk 但没有成功,因为它们需要不再可用的软件(例如 zip-tools)。无论如何,我能够从 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

但是在所有 jar 中,这个服务类都不可用,我唯一可用的实例是 MailMergeType。

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

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

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

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

真诚的

【问题讨论】:

    标签: java libreoffice mailmerge


    【解决方案1】:

    查看this code from 2004,显然您可以简单地使用Java 的Object 类。以下是该代码中的一些 sn-ps:

    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.exehttp://www.willus.com/archive/zip64/

    【讨论】:

    • 你好,吉姆,你完全正确,我在思考这应该如何工作时走错了方向。此外,我在执行作业“DocumentURL”“DataSourceName”“CommandType”“Command”“OutputType”“OutputURL”和“FileNamePrefix”之前设置了这个属性。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-06
    • 1970-01-01
    相关资源
    最近更新 更多