From e9b153095c463186bec37b6e7de74bbbf51949df Mon Sep 17 00:00:00 2001 From: Dolan Date: Wed, 16 May 2018 19:34:25 +0100 Subject: [PATCH] Add demo for custom xml styles --- demo/assets/custom-styles.xml | 2 ++ demo/demo13.js | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 demo/assets/custom-styles.xml create mode 100644 demo/demo13.js diff --git a/demo/assets/custom-styles.xml b/demo/assets/custom-styles.xml new file mode 100644 index 0000000000..76159f2985 --- /dev/null +++ b/demo/assets/custom-styles.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/demo/demo13.js b/demo/demo13.js new file mode 100644 index 0000000000..f141547d7a --- /dev/null +++ b/demo/demo13.js @@ -0,0 +1,26 @@ +// This example shows 3 styles +const fs = require('fs'); +const docx = require('../build'); + +const styles = fs.readFileSync('./demo/assets/custom-styles.xml', 'utf-8'); +const doc = new docx.Document({ + title: 'Title', + externalStyles: styles +}); + +doc.createParagraph('Cool Heading Text').heading1(); + +let paragraph = new docx.Paragraph('This is a custom named style from the template "MyFancyStyle"'); +paragraph.style('MyFancyStyle'); +doc.addParagraph(paragraph); + +doc.createParagraph('Some normal text') + +doc.createParagraph('MyFancyStyle again').style('MyFancyStyle'); +paragraph.style('MyFancyStyle'); +doc.addParagraph(paragraph); + +var exporter = new docx.LocalPacker(doc); +exporter.pack('My Document'); + +console.log('Document created successfully at project root!');