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