我正在尝试通过docx-merger
库合并docx文件。一切都很好,除了Microsoft Word的"Word found unreadable content in output.docx. Do you want to recover the contents of this document? If you trust the source of this document, click Yes."
消息。单击"是"时,它会打开文档,但不是输出文件,只是一个缓冲区。
这是我的代码:
const docxMerger = require('docx-merger');
fs.readdir('input/', (err, bufferFiles) => {
var bufferFilesArr = [];
bufferFiles.forEach(bufferFile => {
var file = fs.readFileSync(path.resolve('app/temps/buffer',bufferFile), 'binary');
bufferFilesArr.push(file);
});
var mergedDocx = new docxMerger({}, bufferFilesArr);
mergedDocx.save('nodebuffer', function(data){{
fs.writeFileSync(path.resolve('output','output.docx'), data, 'utf8',function(err){
//callback
});
}});
});
我在这里尝试合并input
文件夹中docx
文件。
它合并了所有这些,但是如果没有此消息,我无法打开文件。
页眉和页脚部分是此问题的原因。尝试删除文档中的页眉和页脚部分。