[英]How to perform mail merge functionality in java using dot/dotx and doc/docx format document template
我想使用dot / dotx和doc / docx格式的文档在Java中执行邮件合并功能。 我尝试使用docx4j,但它从文档中删除了很多富文本缩进。
我还尝试从Word文档中提取一些html内容,但无法在Word文档中重新粘贴。
public static void readDocxFile1(String fileName) {
// this.file = file;
try {
File file = new File(fileName);
FileInputStream finStream=new FileInputStream(file.getAbsolutePath());
HWPFDocument doc=new HWPFDocument(finStream);
WordExtractor wordExtract=new WordExtractor(doc);
Document newDocument = DocumentBuilderFactory.newInstance() .newDocumentBuilder().newDocument();
WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(newDocument) ;
wordToHtmlConverter.processDocument(doc);
StringWriter stringWriter = new StringWriter();
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8");
transformer.setOutputProperty(OutputKeys.METHOD, "html");
transformer.transform(new DOMSource( wordToHtmlConverter.getDocument()), new StreamResult( stringWriter ) );
String html = stringWriter.toString();
System.out.println("html>>>>>>"+html);
}
catch(Exception e)
{
e.printStackTrace();
}
}
我的要求是,我必须(1)读取点/ dotx或doc / docx模板,然后读取否。 的人将其循环为(2)替换关键字 ,然后(3)在新文档中重新引用它 。
请提出一种如何执行此功能的方法。
另外,请提出针对JAVA的ASPOSE.WORDS API是否会为我完成此建议。
是的,您可以使用Aspose.Words for Java API满足这些要求。 我建议您参考以下文档部分:
我与Aspose一起担任开发人员推广人员。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.