//获取docx文档处理实例
DocxBuilder builder = DocxBuilder.getInstance();
//带有freemarker标记模板的docx文件
String docxFilePath = "docx路径";
File docxFile = new File(docxFilePath);
//需要生成的文件
String targetFilePath = "生成到文件路径";
File targetFile = new File(targetFilePath);
//freemarker替换需要的数据
Map<String,Object> root = new HashMap<String,Object>();
//root.put(key, value);
//解压文件docxFile文件,获取到其中到document.xml文件,该文件带有freemarker到标记
//freemarker根据提供到root数据进行替换
//替换完成后写入到一个指定到文件targetFile
builder.build(docxFile, targetFile, root);
w757227129 / docx_generate Goto Github PK
View Code? Open in Web Editor NEW用最少到代码,生成docx文件。