search

Home  >  Q&A  >  body text

node.js - nodejs合并word文件内容

多个WORD文件内容合并时,只会把第一个WORD的内容写到新的WORD文件里,而其他的WORD内容却不见了。

var fs= require('fs');
var bufferhelper=require('bufferhelper');
var bh= new bufferhelper();
for(var i=0;i<5;i++)
{                
var data=fs.readFileSync('./public/type/xz'+xz[i]+'.doc');
bh.concat(data);
}
fs.writeFileSync('./public/type/jz.doc',bh.toBuffer());    

以上代码运行后,jz.doc里内容只有xz1.doc的内容,至于xz2-5的WORD文件内容却不见了。

PHP中文网PHP中文网2846 days ago1006

reply all(1)I'll reply

  • ringa_lee

    ringa_lee2017-04-17 13:38:30

    The word document format needs to be parsed and cannot be spliced ​​directly like ordinary text files.

    PS: Nodejs probably doesn’t have a better library for parsing Word document format. It’s better to use other languages, such as C# or java

    reply
    0
  • Cancelreply