java - LibreOffice 邮件合并与 Java

标签 java libreoffice mailmerge

我正在尝试从 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。

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

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

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

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

此致

最佳答案

查看 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 工具的来源,请尝试 http://www.willus.com/archive/zip64/ 中的 zip.exe .

关于java - LibreOffice 邮件合并与 Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33478923/

相关文章:

c# - 来自 ASP.NET Web 应用程序的 Word 邮件合并

java - 使用更少的内存需要重新排序数组元素

java - 在 enctype ="multipart/form-data"请求无效后

java - 使用 netty 3.4.2.Final 通过代理工作

linux - 通过 matlab for ubuntu 启动 libreoffice

excel - 如何计算超过 24 小时的持续时间中的小时数?

java - 在 Jersey REST 请求/响应之间存储变量

php - 通过 PHP 编码执行 Linux-CentOS 命令行

vba - 如何拆分邮件合并并以合并字段作为名称保存文件

c# - 通话被被叫方拒绝。 (来自 HRESULT : 0x80010001 (RPC_E_CALL_REJECTED)) 的异常