Jinja based Excel Template support multiple sheets
Project description
Jinja Excel Template Engine
This package can handle some Excel reporting requirements.
It contains:
- Dynamic sheets based on the data
- Images are inside the Excel file,
- Multiple level of grouping in the data (this library does not handle it, but you can have your own data pipeline to prepare the data.),
- Printing header setting,
- Basic charts
This library will not be suitable for you if you are after a completely non-technical maintainable Excel template. In fact, there is none of them, if your Excel template is complicated enough, especially dynamic sheets.
This package will suitable for you for the following scenarios:
- if you have XML knowledge and know how to read openpyxl documents, and
- if you have Jinja2 knowledge
Concept
Excel templating is always complicated and normal Excel file does not support them. We have to use an intermediate file named ExcelXML.
Data + Jinja Template ---(Jinja Engine)---> ExcelXML ---(Excel Generator)---> Excel
With Data and Jinja Template, the Jinja Engine can generate the ExcelXML, then the Excel Generator can generate the Excel file. An ExcelXML is an XML representing a single Excel file.
The ExcelXML has a specific format, so the Excel Generator can read it and draw the Excel.
Here is an example of the ExcelXML.
<Excel>
<sheet sheetName="myFirstSheet" print_area="A1:L10" print_header="1:3">
<row> <!-- first row -->
<cell value="A1" />
<cell value="B1" />
<cell value="C1" />
</row>
<row /> <!-- second row, empty row -->
<row> <!-- third row -->
<cell value="A3" />
<cell value="B3" />
<cell value="C3" />
</row>
</sheet>
<sheet sheetName="mySecondSheet" print_area="A1:L10" print_header="1:3">
<row> <!-- first row -->
<cell value="A1" />
<cell value="B1" />
<cell value="C1" />
</row>
<row /> <!-- second row, empty row -->
<row> <!-- third row -->
<cell value="A3" />
<cell value="B3" />
<cell value="C3" />
</row>
</sheet>
</Excel>
The Jinja template is to construct the ExcelXML with your own data pipeline.
Why did I chose XML not JSON? JSON is too messy to representing meta data and attributes, so I chose XML.
Sample
Please check the tests/countries.py
. It shows the raw data and group countires by region and display countries in multiple sheets. It also contains some basic diagrams.
If you are interested in more complicated example, you can refer to tests/test.xml
that is the test XML I am using to test my output and it finally hit 99% code coverage.
TODO list
- Filtering and grouping
- Auto column width (the current implement is not good enough)
- Calculated cell
- Auto number, date and text detection
- Spend more time on openpyxl document (yes unfortunately, I haven't got enough time)
- Pivot table?? (not sure the use case about it, put it in low priority)
About me
I am from .NET, Java and NodeJS background. This is my first project in Python. When I started this project, I wanted to go to NodeJS, but ExcelJS is not powerful enough comparing to openpyxl. That is why I chose Python. If I am not good at the Python standard, please let me know by email hkalex@gmail.com. Thanks.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for jinja_excel_template-1.0.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1539b2acda22cded8b6802ae523e429fc64ce499f7c1ca20e635bd34b048421b |
|
MD5 | b6aaca3dd620e02dddb5a2dc25df3a89 |
|
BLAKE2b-256 | 7708591695ec39d1c98a8cdb216b8f580e98444eec444c5955a3b1e16cad9d38 |
Hashes for jinja_excel_template-1.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f171caf8473c5864eede024b5f2b9fcb7260d6e1e097e60d7ba2212da279a61 |
|
MD5 | 753426ba6d7f8a215593a86ca91afdcc |
|
BLAKE2b-256 | a34c50bbca77c080d03513713ee79261a4ad5e6e1b4fc411b78c7ff79b768786 |