Creating an xlsm from an existing xlsm loses macros #606

Closed
opened 2017-03-27 21:48:39 +00:00 by johnothetree · 4 comments
johnothetree commented 2017-03-27 21:48:39 +00:00 (Migrated from github.com)

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?

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?
SheetJSDev commented 2017-03-27 22:16:53 +00:00 (Migrated from github.com)

@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");
	}
  1. 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 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));`: ```js 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 */});
SheetJSDev commented 2017-03-28 04:43:16 +00:00 (Migrated from github.com)

@johnothetree we just pushed the aforementioned changes and they will appear in the next release

@johnothetree we just pushed the aforementioned changes and they will appear in the next release
johnothetree commented 2017-03-28 14:36:52 +00:00 (Migrated from github.com)

@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?

@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?
SheetJSDev commented 2017-03-28 14:51:07 +00:00 (Migrated from github.com)

we're aiming for Friday.

we're aiming for Friday.
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/sheetjs#606
No description provided.