What's the best way to use officegen in a loop when trying to create large volumes of files.

瀏覽次數:45 次
跳到第一則未讀訊息

James Swandale

未讀,
2017年3月6日 下午1:11:072017/3/6
收件者:node.js officegen package
Hi there, 

I'm trying to create a batch of files with varying content and I'm running in to some strangeness. It may be my unfamiliarity with node streams but I'm wondering if you can help.

The actual content of the files doesn't seem to be written till the entire loop has finished, say I'm making 1000 files, it seems to create a thousand empty files then after that writes the data to them. This causes me to run in to a load of memory errors and everything falls over.

I think I'm missing something :)

Excerpt below, it's pretty basic stuff.


for (var j = nrOfFiles; j > 0; j--) {
fileName = 'randomFileNumber'+j;
filePath = 'tmp2/'+fileName+'.docx';

docx.setDocTitle(fileName);
pObj = docx.createP ();
pObj.addText("test");

out = fs.createWriteStream (filePath);
docx.generate (out);
}
回覆所有人
回覆作者
轉寄
0 則新訊息