Skip to main content

A python module to generate xls files from a xls template

Project description

xlstpl

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

How it works

xlstpl uses xlrd to read and use xlwt to write .xls files, uses jinja2 as its template engine.
When xlstpl reads a .xls file, it creates a tree for each worksheet.
Then, it translates the tree 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 file.

Syntax

xlstpl uses jinja2 as its template engine, follows the syntax of jinja2 template.

Each worksheet is translated to a jinja2 template with custom tags.

...
...
{% row 45 %}
{% cell 46 %}{% endcell %}
{% cell 47 %}{% endcell %}
{% cell 48 %}{{address}}  {%xv v%}{% endcell %}
{% cell 49 %}{% endcell %}
{% cell 50 %}{% endcell %}
{% cell 51 %}{% endcell %}
{% cell 52 %}{% endcell %}
{% cell 53 %}{% endcell %}
{% row 54 %}
{% cell 55 %}{% endcell %}
{% cell 56 %}{% sec 0 %}{{name}}{% endsec %}{% sec 1 %}{{address}}{% endsec %}{% endcell %}
...
...
{% for item in items %}
{% row 64 %}
{% cell 65 %}{% endcell %}
{% cell 66 %}{% endcell %}
{% cell 67 %}{% endcell %}
{% cell 68 %}{% endcell %}
{% cell 69 %}{% endcell %}
{% cell 70 %}{% endcell %}
{% cell 71 %}{% endcell %}
{% cell 72 %}{% endcell %}
{% endfor %}
...
...

xlstpl added 4 custom tags: row, cell, sec, and xv.
row, cell, sec are used internally, used for row, cell and rich text.
xv is used to define a variable.
When a cell contains only a xv tag, this cell will be set to the type of the object returned from the variable evaluation.
For example, if a cell contains only {%xv amt %}, and amt is a number, then this cell will be set to Number type, displaying with the style set on the cell.
If there is another tag, it is equivalent to {{amt}}, will be converted to a string.

Installtion

pip install xlstpl

How to use

See examples.

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

xlstpl-0.2.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

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

xlstpl-0.2-py2.py3-none-any.whl (13.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file xlstpl-0.2.tar.gz.

File metadata

  • Download URL: xlstpl-0.2.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.0

File hashes

Hashes for xlstpl-0.2.tar.gz
Algorithm Hash digest
SHA256 7427819b6146600ebd5266e584ce597cfb90d607b1ea2e20fea1ff9dea66ce4b
MD5 52be0aabb30fdb465616ac5af24d52d3
BLAKE2b-256 756b9270d6a412167047c7a7142c34d1c9cc2e5052c30d2c81e40a71e14d807f

See more details on using hashes here.

File details

Details for the file xlstpl-0.2-py2.py3-none-any.whl.

File metadata

  • Download URL: xlstpl-0.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.0

File hashes

Hashes for xlstpl-0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 de8da17be7e5368c2ad1600315a3fcd50974c02743defbce1d88f805aecb1c9a
MD5 a3b175e61584795c20ff8371febf98e8
BLAKE2b-256 3d3ba0ee54ecdbf2c2d26acd86983df3469c2d99913960b11bd514fe4db43711

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