1、概述
在分析过docx文档结构后,可知其主要由xml文件和资源构成,主要的文本内容存于document.xml文件中。理解docx文档结构对于了解docx-merger、docx、docxtemplater等一些插件操作docx的实现原理很有帮助。
2、常见的操作文档的需求
在实际项目中,会遇到很多需要操作docx文档的需求。例如:
- 将两个文档的内容合并到一个文档里
- 自定义格式和内容生成一个文档
- 根据用户填写的固定格式的表单数据生成固定格式的文档
- 在线预览docx文档
对于以上问题都有许多解决方案,我只是基于自己的使用情况做了一些总结,以供参考。
3、基于docx-merger实现内容合并
使用示例
var DocxMerger = require('docx-merger');
var fs = require('fs');
var path = require('path');
var file1 = f