如何使用 Java 将数据插入 Microsoft Word 模板?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17693553/
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-11-01 14:42:33  来源:igfitidea点击:

How to insert data into a Microsoft Word Template using Java?

javams-wordword-template

提问by B.K.

I have a map of data that I want to insert into fields in an existing Microsoft Word Template. Preferably, I'd like to accomplish it using Java. I extracted text from a pdf file and then parsed it for data. Now, I need to figure out how to insert that data into a word template, which serves as a form. By data, I mean things such as name, address, etc.

我有一张数据地图,想插入到现有 Microsoft Word 模板的字段中。最好,我想使用 Java 来完成它。我从 pdf 文件中提取文本,然后解析它的数据。现在,我需要弄清楚如何将该数据插入到用作表单的单词模板中。通过数据,我的意思是诸如姓名、地址等。

Is it even possible? I haven't been able to locate any documentation or references that would help me with this task. I've been able to find some stuff on creating MS Word documents, but nothing as far as insertion into template text fields.

甚至有可能吗?我找不到任何可以帮助我完成此任务的文档或参考资料。我已经能够找到一些关于创建 MS Word 文档的东西,但就插入到模板文本字段而言,一无所获。

回答by sTella

I've used JWordseveral times to create documents from template. It's not free but accomplished what I needed.

我已经多次使用JWord从模板创建文档。它不是免费的,但完成了我所需要的。

回答by saimiris_devel

I suggest the ODFDOMproject for ODF documents (LibreOffice, OpenOffice open document format, not Microsoft MOOXML format).

我建议ODF 文档的ODFDOM项目(LibreOffice、OpenOffice 开放文档格式,而不是 Microsoft MOOXML 格式)。

You can load an ODF document and modify variables inside it, style and content or you can create a document from scratch.

您可以加载 ODF 文档并修改其中的变量、样式和内容,也可以从头开始创建文档。

The project is quite active, the latest version available is 2014-06-02 - ODF Toolkit 0.6.1-incubating.

该项目非常活跃,可用的最新版本是 2014-06-02 - ODF Toolkit 0.6.1-incubating。