使用java从模板创建word文档 [英] Creating word document from a template using java

查看:55
本文介绍了使用java从模板创建word文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个包含文本部分、复选框和表格的 Word 文档.我想为这个文档创建一个模板,并使用该模板使用java创建一个word文档.

I want to create a word document which has a text part, checkboxes and tables in it. I want to create a template of this document and use the template to create a word document using java.

谁能给我建议一个最简单的方法来做同样的事情.我尝试做 xml 映射,但它只适用于文本和表格.我比较关心word文档中的复选框.

Can anyone please suggest me an easiest way to do the same. I tried doing xml mapping but it only works fine with text and tables. I am more concerned about the checkboxes in the word document.

请帮忙!

推荐答案

我玩了一个绑定复选框内容控件.

I had a play with a bound checkbox content control.

我发现当您选中/取消选中文档表面上的复选框时,Word 会更新自定义 xml 部分,但是当您更改 word 外自定义 xml 部分中的值时,该复选框不会自动更新.在 Word 2010 之外更新选中状态 (w14:checkbox/w14:checked) 也是不够的:它似乎被忽略了.

I found that Word updates the custom xml part when you check/uncheck the checkbox on the document surface, but that the checkbox doesn't automatically update when you change the value in the custom xml part outside word. Nor is it enough to update the checked state (w14:checkbox/w14:checked) outside Word 2010: it seems to be ignored.

换句话说,与绑定文本内容控件不同,更新不是双向的.

In other words, unlike for bound text content controls, the update isn't bi-directional.

因此,要完成这项工作,您需要自己应用绑定(即将 sdtContent 更改为选中或未选中的框).

So to make this work, you'd need to apply the binding yourself (ie alter the sdtContent to be a checked or unchecked box).

在 Java 实现方面,docx4j 2.7.1 可以为文本内容控件应用绑定,但需要一个小补丁插入选中或未选中的框.

In terms of Java implementations, docx4j 2.7.1 can apply bindings for text content controls, but would need a minor patch to insert the checked or unchecked box.

这篇关于使用java从模板创建word文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆