After installing the module, you can use a working demo by running node sample.js
.
This module exposes multiple tags to dynamically change the style of a given paragraph, table cell or table row.
The current tags are :
{:stylecell s1}
To style a cell{:stylepar s2}
To style a paragraph{:stylerow s3}
To style a whole row in a table{:stylebullets s4}
To style a bulleted list (change bullets color){:styleshape s5}
To style a shape (for example, the fillColor of a rectangle){:stylerun s6}
To style part of a paragraph that already has one style.Your docx should contain the text: {:stylecell style}
.
const StyleModule = require("docxtemplater-style-module");
const doc = new Docxtemplater(zip, {
modules: [new StyleModule()],
});
doc.render({
style: {
cellBackground: "#00ff00",
textColor: "white",
fontFamily: "Calibri",
},
});
To style a paragraph, you can use following styles :
Of course, one would normally only use some of those style properties, not all at the same time.
doc.render({
cellBackground: "#00ff00",
textColor: "white",
textAlign: "center", // justify,center,left,right
pStyle: "Heading",
fontSize: 22,
fontFamily: "Calibri",
borders: {
top: {
val: "single",
sz: 36,
space: 8,
color: "#FF0000",
},
},
});
To style a run, you can use following styles :
{
"textColor": "white",
"fontFamily": "Calibri",
"italic": true,
"bold": true,
"underline": true
}
To style a shape, you can use the following styles :
{
"fillColor": "#ff0000",
"strokeColor": "#00ff00"
}
To style a list of bullets, you can use following styles :
{
"bulletColor": "#00ff00"
}
To style a cell, you use the {:stylecell s1}
tag. To style all cells in a given row, you use the {:stylerow s1}
tag.
You can use following styles :
{
"cellBackground": "#00ffff",
"borders": {
"top": {
"val": "single",
"sz": 36,
"space": 8,
"color": "#FF0000"
}
}
}
And all style properties from Paragraph Styling
It is possible to change the colors of the currently used theme by using following code :
const StyleModule = require("docxtemplater-style-module");
const styleModule = new StyleModule();
const doc = new Docxtemplater(zip, {
modules: [styleModule],
});
styleModule.setThemeColors({
"a:dk1": "000000",
"a:lt1": "FFFFFF",
"a:dk2": "1F497D",
"a:lt2": "EEECE1",
"a:accent1": "4F81BD",
"a:accent2": "C0504D",
"a:accent3": "9BBB59",
"a:accent4": "8064A2",
"a:accent5": "4BACC6",
"a:accent6": "F79646",
"a:hlink": "0000FF",
"a:folHlink": "800080",
});
doc.render({
style: {
cellBackground: "#00ff00",
textColor: "white",
fontFamily: "Calibri",
},
});
Note that the call to the "setThemeColors" function should be done after the instatiation of the Docxtemplater instance and before the call to the "render" method.
Bugfix corruption when using cellBackground on shape that uses "
Make it possible to use prefix from the constructor
Add typescript typings to be able to change the module prefix
Add support for bold
, underline
, italic
.
Add typescript typings for styleModule.setThemeColors
Upgrade module to use NodeNext moduleResolution setting. See explanation here
Use new resolvedId
API => requires docxtemplater@3.43.0
Bugfix to allow to change fontSize inside docx shape.
Fix bug when using renderAsync and parser compilation fails : the error should now be shown inside a multierror. To to this, we now use sm.getValueAsync
in resolve instead of sm.getValue
Bugfix to set or get xml attributes correctly, even when using tabs instead of spaces in tags attributes
Set module.priority in order to have no more issues related to module ordering
Bugfix error when running asynchronously :
Upgrade to correctly pass in fileType, contentType, … to resolve
Makes it compatible with docxtemplater 3.40.1
Make styling module compatible with docxtemplater@3.40.0
With {:styleshape style1}, allow to change fillColor
of normal textboxes in Powerpoint.
Add module.clone() internal to make module work well with subsegment module
Bugfix following error :
When using the styling module in async mode (calling doc.renderAsync()
) with some empty data for one of the styling tags.
Add support to change borders for tables (not just for paragraphs)
Add support for setting "fontSize".
Bugfix of stacktrace thrown when used in async mode with doc.renderAsync();
The error was :
Now the error will no more show up and the template will render correctly even in async mode.
Add possibility to change themeColors using styleModule.setThemeColors()
API
Avoid issue Cannot read properties of undefined (reading 'value')
when using the module asynchronously with Slides module, and having the data return synchronously.
Avoid possible issue of "Maximum call stack size exceeded"
Fix typescript definition file :
Previously, when writing import StyleModule from "docxtemplater-style-module";
, the following error would be shown :
Add support for textAlign: "right" , "center", "justify".
Update to make module compatible with docxtemplater@3.30.0
Fixes following error :
When using stylerun module near a loop, the following error could sometimes appear :
Now this error should no more appear.
Bugfix to correctly change bulletcolor when using a paragraphStyle
Bugfix to correctly be able to change shapes in PPTX documents when using "description" of shape.
Make package size smaller
Avoid errors when using "bulletColor" on paragraphs that are not bullets : in this case, previously, docxtemplater would crash with "Cannot read property indexOf" of undefined. Now, this property is ignored in this case
:stylepar tag should be placed inside a paragraph
when using {:stylepar xxx}
tag inside a Powerpoint titleAdd support for "borders" to set or update paragraph borders.
Bugfix {:stylerun} to correctly style run even when there is a "w:drawing" (a picture) defined inside the run.
Bugfix {:stylerun} to correctly style run even when there is a "mc:AlternateContent" (a shape) defined inside the run.
Bugfix {:stylerun} to remove the "w:themeColor" and "w:themeTint" attributes before styling a run.
Add {::stylerun}
tag to be able to edit the rStyle
of the run.
{:stylerun}
tag now doesn't leak into other runs or other paragraphs.
Make {textColor: "#ff0000"}
work well in all cases (previously, it worked only if a <w:rPr>
tag was present in the docx file for that particular run)
Make stylerun and stylebullets work together even when both are specified in the same run.
Add possibility to add multiple {:stylerow}
tags in the same table cell (to be able to put several conditions).
Bugfix to make {:stylerun s2}
work correctly (eg expand the whole run, even if there are multiple runs with the same exact properties).
Bugfix following error :
when using the stylebullets and stylerun tag together
Add tags for styling bullets and tag for styling runs of text.
{:stylebullets s1}
and {:stylerun s2}
Make module compatible with docxtemplater@3.28.0. Please make sure to update docxtemplater to 3.28.0 at the same time you update this module. The internal change made is the use of the new matchers API which fixes bugs that were triggered depending on the order of the modules that are attached to the instance. Now the order of the modules should not matter as expected.
Make module work in async mode : in previous versions, the message : TypeError: Cannot read properties of undefined (reading 'indexOf')
could occur.
Make module compatible with docxtemplater@3.27.0. Please make sure to update docxtemplater to 3.27.0 at the same time you update this module
Add support to use {:styleshape s1}
inside the description of the shape.
[pptx] Add support for {:styleshape s1}
for Powerpoint documents (fillColor and strokeColor)
[docx] Add support for {:styleshape s1}
to change the fillColor and strokeColor of a shape.
doc.render({
s1: {
fillColor: "#554499",
strokeColor: "#000000",
},
});
Add support to also add text after changing the style, for example :
doc.render({
s1: {
text: "Hello John !",
fontFamily: "Bahnschrift",
textColor: "#554499",
},
});
Use @xmldom/xmldom instead of xmldom, see this github issue
Generate files in built with correct filename In previous versions, the filename was always build/docxtemplater.js
. Now the filename is build/style-module.js
The .min.js file is also created now.
Add typescript definitions for public API
Move webpack from dependency to devDependency (which triggered an error during installation on node version 10)
Internal change to allow to match tags with non-breaking space.
When entering Ctrl+Shift+Space
, a "non-breaking" space is created.
When using a non-breaking space in the tag {:stylecell style}
, the tag would not be replaced correctly.
Update to make module work in the browser
Add support for pptx
Add {:stylerow}
tag
Require docxtemplater 3.17.6
Declare supportedFileTypes, which allows to use this module with the new docxtemplater constructor which was introduced in docxtemplater 3.17.
Update browser build to use XMLSerializer instead of xmldom
Use requiredAPIVersion
Explanation : On some versions of npm (notably 5.8.0), when having a package containing docxtemplater-styling-module, the installation will generate a tree of node_modules that puts the module on a level where it has no access to docxtemplater. By explicitly asking it as a dependency, this issue is avoided.
Explanation : Recently, the scopemananger API (internal API) has changed, this new version of the styling module makes the module work with both versions newer than 3.6 and older than 3.6 of docxtemplater.
Add meta context argument to custom parser with information about the tag for each types of tags
Add the {:stylepar style}
tag to change the paragraph style
Add support for fontFamily: "Calibri"
Refactor module.prefix into an object {cell: ':stylecell', paragraph: ':stylepar'}
Initial release