当前位置: 首页 > 工具软件 > dotX > 使用案例 >

java dot模板怎么使用_如何使用dot / dotx和doc / docx格式文档模板在java中执行邮件合并功能...

季骏祥
2023-12-01

我想使用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) read a dot/dotx or doc/docx template 和否 . 人们循环到 (2) replace the keywords 然后 (3) repasting it in the new document .

请建议一种方法如何执行此功能 .

另请建议,如果JAVA的ASPOSE.WORDS API将为我这样做 .

 类似资料: