来自 Java 的邮件合并

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2380441/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 20:52:52  来源:igfitidea点击:

Mail merge from Java

javadocxdocmailmerge

提问by Mike Q

Does anyone have any experience with doing mail merge from Java on a word document? I need to support both doc and docx formats.

有没有人有在 Word 文档上从 Java 进行邮件合并的经验?我需要同时支持 doc 和 docx 格式。

I have heard of Apache POI and docx4j. However, from reading around I'm sure how good the word support is in POI. docx4j only supports docx format as far as I can see.

我听说过 Apache POI 和 docx4j。但是,通过阅读,我确信 POI 中的支持一词有多好。据我所知,docx4j 仅支持 docx 格式。

Can any suggest either one of the above (and correct my knowledge on support) or another appropriate library. If necessary I would be willing to use one lib for doc and another for docx.

任何人都可以建议上述之一(并纠正我的支持知识)或其他合适的图书馆。如有必要,我愿意为 doc 使用一个库,为 docx 使用另一个库。

Thanks.

谢谢。

回答by Piotr Kochański

Working with MS Word documents is very hard. DOC format is very complicated, DOCX is in theory simpler, but it is rather new and there is no mature, feature rich Java library to work with it and DOC as well.

使用 MS Word 文档非常困难。DOC 格式非常复杂,理论上 DOCX 更简单,但它是相当新的,并且没有成熟的、功能丰富的 Java 库来处理它和 DOC。

The easiest solutions to most problems connected with working with MS Office documents is describe in the Joel Spolsky article. I hope you can use this method in your application.

对于与使用 MS Office 文档相关的大多数问题,最简单的解决方案在Joel Spolsky 文章中有所描述。我希望您可以在您的应用程序中使用这种方法。

回答by Marcin

Docx4jhas a MailMergerclass. It works, but it strips out a lot of formatting in the process.

Docx4j有一个MailMerger类。它有效,但它在此过程中删除了很多格式。

回答by Brad Mace

If you're open to non-free solutions, Aspose provides what appears to be a very sophisticated Java API for mail merging, among other things.

如果您对非免费解决方案持开放态度,那么 Aspose 提供了看起来非常复杂的Java API 用于邮件合并等。

回答by Paul Jowett

Have a look at OpenOffice to see [manually] whether it can produce the types of files you need. Just load up some docs, and save some docs and docx versions. If the results pass these simple manual tests, then Docmosisor JODReportscan automate this from Java.

看看 OpenOffice 看看[手动]它是否可以生成您需要的文件类型。只需加载一些文档,并保存一些文档和 docx 版本。如果结果通过了这些简单的手动测试,则DocmosisJODReports可以从 Java 自动执行此操作。

回答by centic

I needed something similar and have built a simple project which allows to do a mail-merge of a word document and data from an Excel/CSV file.

我需要类似的东西,并构建了一个简单的项目,该项目允许对 Word 文档和 Excel/CSV 文件中的数据进行邮件合并。

You can find it at https://github.com/centic9/poi-mail-merge, maybe it already provides what you need here, otherwise it is hopefully easy to add more features.

您可以在https://github.com/centic9/poi-mail-merge找到它,也许它已经在这里提供了您需要的东西,否则希望可以轻松添加更多功能。