0.3.0 • Published 2 years ago

xltpl v0.3.0

Weekly downloads
2
License
MIT
Repository
github
Last release
2 years ago

xltpl ( node-xlsx-template )

A node module to generate .xlsx files from a .xlsx template.

How it works

When xltpl reads a xlsx file, it creates a tree for each worksheet.
And, each tree is translated to a nunjucks(jinja2) template with custom tags.
When the template is rendered, nunjucks extensions of cumtom tags call corresponding tree nodes to write the xlsx file.

How to install

npm install xltpl

How to use

  • To use xltpl, you need to be familiar with the syntax of nunjucks template.
  • Get a pre-written xls/x file as the template.
  • Insert variables in the cells, such as :
{{name}}
  • Insert control statements in the cells :
{%- for row in rows %}
{% set outer_loop = loop %}{% for row in rows %}
Cell text
{{outer_loop.index}}{{loop.index}}
{%+ endfor%}{%+ endfor%}
  • Run the code
let BookWriter = require('xltpl');
function run() {
    let writer = new BookWriter();
    let p = writer.readFile('template.xlsx');
    p.then(async function () {
        let payloads = await getPayloads();
        writer.renderSheets(payloads);
        await writer.save('result.xlsx');
    })
}
run();

See examples.

CodeSandbox examples

Supported

  • MergedCell
  • Non-string value for a cell (use {{variable}} with no leading or trailing spaces or {%xv variable%} to specify a variable)
  • Image (use {%img variable%})
  • DataValidation
  • AutoFilter

Related

0.3.0

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.9

2 years ago

0.2.8

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.1.0

5 years ago