Giter Site home page Giter Site logo

zhangyu836 / node-xlsx-template Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 0.0 122 KB

A node module to generate xlsx files from a xlsx template

License: MIT License

JavaScript 100.00%
spreadsheet spreadsheet-manipulation template excel exceljs workbook workbook-writer nunjucks jinja

node-xlsx-template's Introduction

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

node-xlsx-template's People

Contributors

zhangyu836 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.