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

45 views
Skip to first unread message

James Swandale

unread,
Mar 6, 2017, 1:11:07 PM3/6/17
to 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);
}
Reply all
Reply to author
Forward
0 new messages