Skip to main content

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.

Metadata

Release files for xltpl 0.21

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xltpl 0.21
File Size Uploaded
xltpl-0.21.tar.gz 24.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for xltpl 0.21
File Interpreter ABI Platform
xltpl-0.21-py3-none-any.whl Python 3 none any Details

Total release size: 52.7 kB

Release files / xltpl-0.21.tar.gz

Download URL xltpl-0.21.tar.gz
Size 24.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b1970cd64f64ef18cf8deeedd9cbf6ad13de92d71ddffbff4cc70eaad20d61d0
BLAKE2b-256 checksum
How to use checksums
aab51cf3356a0dcd77c3e378cd133adf976998173100ee6709b01a0a97673ceb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.0

Release files / xltpl-0.21-py3-none-any.whl

Download URL xltpl-0.21-py3-none-any.whl
Size 28.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
422a84235f25df389815788eb4f4bcf33414fcf4f665cf5545c0186ba6896c2c
BLAKE2b-256 checksum
How to use checksums
ce2647018d8aa5e7e721f8ec780582671a29002fc70f48d956608d6b23585da4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.0

Release history Release notifications | RSS feed

This release

0.21 This release

2 release files

0.20

2 release files

0.19

2 release files

0.18

2 release files

0.17

2 release files

0.16

2 release files

0.15

2 release files

0.14

2 release files

0.13

2 release files

0.12.1

2 release files

0.12

2 release files

0.11

2 release files

0.10.1

2 release files

0.10

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9

2 release files

0.8

2 release files

0.7

2 release files

0.6

2 release files

0.5.1

2 release files

0.5

2 release files

0.4.1

2 release files

0.4

2 release files

0.3.1

2 release files

0.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page