js实现多个word合并,使用docx-merger库

npm i -s docx-merger
var DocxMerger = require("docx-merger");

var fs = require("fs");
var path = require("path");

var file1 = fs.readFileSync(
  path.resolve(__dirname, "1.docx"),
  "binary"
);

var file2 = fs.readFileSync(
  path.resolve(__dirname, "2.docx"),
  "binary"
);

var docx = new DocxMerger({}, [file1, file2]);

//SAVING THE DOCX FILE

docx.save("nodebuffer", function (data) {
  // fs.writeFile("output.zip", data, function(err){/*...*/});
  fs.writeFile("output.docx", data, function (err) {
    /*...*/
  });
});

todo

页面方式使用

你可能感兴趣的:(javascript,word,前端)