dolanmiu / docx

Easily generate and modify .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.
https://docx.js.org/
MIT License
4.38k stars 484 forks source link

Docx Macros (docm) #471

Open mmdonaldson opened 4 years ago

mmdonaldson commented 4 years ago

As far as I know there is no way to include a macro in a word document and export as a .docm file.

From what I can tell, unziping a .docm gives you the raw files that are embedded in the file.

Interested to know the appetite is for an api similar to styles to allow for macro word docs.

E.g. something along the lines of:

const vbaData = fs.readFileSync('./vbaData.xml');
const vbaProject = fs.readFileSync('./vbaProject.bin');
const doc = new docx.Document({
  title: 'Title',
  vbaData,
  vbaProject,
});

Haven't actually played around with this yet so any known info/issues would be keen to know

dolanmiu commented 4 years ago

What is a macro? code? What is the use of it?

mmdonaldson commented 4 years ago

All the Microsoft products (Word/Excel etc) have a thing called macros which allows you to write a script (VBA or C#) to automate a task you might want to do on a file.

Handy for things repetitive stuff you might do on every file.

https://support.office.com/en-us/article/create-or-run-a-macro-c6b99036-905c-49a6-818a-dfb98b7c3c9c

dolanmiu commented 4 years ago

I prefer the idea of adding the code in like:

const doc = new docx.Document({
  title: 'Title',
  scripts: ['visual basic code'],
});

Rather than injecting the entire xml file in, but I don't know, may need to do more research

mmdonaldson commented 4 years ago

Agree that'd be nicer, but I think the code is baked into a project file. Will do some investigation and report back.