我需要执行以下操作(使用Grails):
- Read a word template
- Add user details (e.g. name, last name) to the document
- Send the customized word by mail
我想在Apache POI中阅读.doc,然后在文档中输入关键字,例如“°!”#$”并进行自定义。
然后,我将创建文档,将其发送(带有Grails插件)并从服务器中删除该文档
这是一个好方法还是我忘记了什么?
非常感谢你
编辑:
DOCx4j:我的docx操作很简单,因此我可以使用变量replace中的“方法1”,
但由于某种原因,下一个示例对我不起作用:
https://github.com/plutext/docx4j/blob/master/src/samples/docx4j/org/docx4j/samples/VariableReplace.java
我得到:
| Error 2014-03-27 09:10:23,640 [http-bio-9000-exec-5] ERROR errors.GrailsExceptionResolver - SAXParseException occurred when processing request: [POST] /Estrategia/pasantiaCorta/generarDocumento
Content is not allowed in prolog.. Stacktrace follows:
Message: Content is not allowed in prolog.
在该行中:
//方法1(从3.0.0开始;如果尚未引起解码,则速度更快):
documentPart.variableReplace(mappings);
最佳答案
当然,您可以使用POI或docx4j。无论哪种方式,使用docx都会比使用传统的二进制doc格式更好。
对于docx4j(我的项目),请参见creating-word-docx-documents-dynamically-from-grails
在第2步(添加用户详细信息)时,可以使用variety of approaches。
关于grails - Grails-阅读,自定义和附加Word文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22620735/