I'm attempting to modify an existing xlsm file using SheetJS and running into this issue. After reading in the information, making my changes, and then writing it back out, it doesn't keep the macros on the new file that's created. Is there a way to copy the macros from the original xlsm to the new xlsm file?
@johnothetree the current version does not round-trip macros, but fortunately this is really easy to fix! Feel free to make the change and submit a PR:
1) in the bits/30_ctypes.js file, after the line f3('themes') add a line f3('vba'). This tells the writer to include an entry in [Content_Types].xml
2) in the file bits/86_writezip.js add the following just before the line zip.file("[Content_Types].xml", write_ct(ct, opts));:
if(wb.vbaraw) {
f = "xl/vbaProject.bin";
zip.file(f, wb.vbaraw);
ct.vba.push(f);
add_rels(opts.wbrels, ++rId, "vbaProject.bin", "http://schemas.microsoft.com/office/2006/relationships/vbaProject");
}
3) in your code, make sure to pass the option bookVBA:true. For example, if you are using XLSX.readFile, you could write something like `XLSX.readFile("filename", {bookVBA:true, /* .. other options */});
@johnothetree we just pushed the aforementioned changes and they will appear in the next release
@SheetJSDev perfect, thanks! any idea when the next release will be? or should i go ahead and manually add the changes locally as it'll be a lil while yet?
we're aiming for Friday.