Skip to main content

A python module to generate xls/x files from a xls/x template

Project description

xltpl

A python module to generate xls/x files from a xls/x template.

How it works

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

How to install

pip install xltpl

How to use

  • To use xltpl, you need to be familiar with the syntax of jinja2 template.
  • Get a pre-written xls/x file as the template.
  • Insert variables in the cells, such as :
{{name}}
  • Insert control statements in the notes(comments) of cells, use beforerow, beforecell or aftercell to seperate them :
beforerow{% for item in items %}
beforerow{% endfor %}
  • Insert control statements in the cells (v0.9) :
{%- for row in rows %}
{% set outer_loop = loop %}{% for row in rows %}
Cell
{{outer_loop.index}}{{loop.index}}
{%+ endfor%}{%+ endfor%}
  • Run the code
from xltpl.writerx import BookWriter
writer = BookWriter('tpl.xlsx')
person_info = {'name': u'Hello Wizard'}
items = ['1', '1', '1', '1', '1', '1', '1', '1', ]
person_info['items'] = items
payloads = [person_info]
writer.render_book(payloads)
writer.save('result.xlsx')

Supported

  • MergedCell
  • Non-string value for a cell (use {% xv variable %} to specify a variable)
  • For xlsx
    Image (use {% img variable %})
    DataValidation
    AutoFilter

Related

Notes

xlrd

xlrd does not extract print settings.
This repo does.

xlwt

xlwt always sets the default font to 'Arial'.
Excel measures column width units based on the default font.
This repo does not.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xltpl-0.20.tar.gz (24.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xltpl-0.20-py3-none-any.whl (28.4 kB view details)

Uploaded Python 3

File details

Details for the file xltpl-0.20.tar.gz.

File metadata

  • Download URL: xltpl-0.20.tar.gz
  • Upload date:
  • Size: 24.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.0

File hashes

Hashes for xltpl-0.20.tar.gz
Algorithm Hash digest
SHA256 ff326935766db3aba7007e62d23f79f6a855e8ce6e9b8c6cf33191b4697a8f10
MD5 1c8891a1ee1fdb584514cdfec0499ebb
BLAKE2b-256 84eaaff4eef3a8e94623bafa5d02d14a6f3c65c52ab56e673f1715f946201a52

See more details on using hashes here.

File details

Details for the file xltpl-0.20-py3-none-any.whl.

File metadata

  • Download URL: xltpl-0.20-py3-none-any.whl
  • Upload date:
  • Size: 28.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.0

File hashes

Hashes for xltpl-0.20-py3-none-any.whl
Algorithm Hash digest
SHA256 7fd9e62a7dd268bdf0ba483ec9fec5ef204f827c3348b6ccb2550ebb4276b1d8
MD5 6bf9e915024f861c7643f007bb694a85
BLAKE2b-256 069b81e7808a69b360dbcb7d1e089ce90c90bb2eaa8cceb1120141e407a903fd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page