Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

xltpl

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xltpl

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

  • 0.21
  • PyPI
  • Socket score

Maintainers
1

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

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.

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc