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.
Metadata
Release files for xlstpl 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| xlstpl-0.2.1.tar.gz | 12.8 kB | Without provenance | Details for xlstpl-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| xlstpl-0.2.1-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for xlstpl-0.2.1-py2.py3-none-any.whl |
Total release size: 26.1 kB
Release files / xlstpl-0.2.1.tar.gz
| Download URL | xlstpl-0.2.1.tar.gz |
|---|---|
| Size | 12.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
76eb33a2a15807837314b9c6534e891c93da8745873798699d4ca5e803a53c5b
|
|
BLAKE2b-256 checksum How to use checksums |
4a7db0afb2aae19bb025bf361cd22d1b95333a5fcfac56b6fcf5d3dfce3ce998
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / xlstpl-0.2.1-py2.py3-none-any.whl
| Download URL | xlstpl-0.2.1-py2.py3-none-any.whl |
|---|---|
| Size | 13.4 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
99aa5447463940ea65dbe46fd78841aadcedc9a019f2e67ca95bce4a953b0316
|
|
BLAKE2b-256 checksum How to use checksums |
6cd5670f7bf24b4b88f32bd677bff74acef4d80bbafb0df1e4bac91f4c34c826
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for xlstpl 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.