jinja-excel-template


Namejinja-excel-template JSON
Version 1.0.4 PyPI version JSON
download
home_pagehttps://github.com/hkalex/jinja-excel-template
SummaryJinja based Excel Template support multiple sheets
upload_time2023-09-25 01:42:18
maintainer
docs_urlNone
authorAlexYeung
requires_python>=3.10,<4.0
licenseMIT
keywords jinja excel template engine xlsx multi-sheet multiple sheets dynamic sheets
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Jinja Excel Template Engine

This package can handle some Excel reporting requirements.

It contains:

1. Dynamic sheets based on the data
2. Images are inside the Excel file,
3. 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.),
4. Printing header setting,
5. 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:
1. if you have XML knowledge and know how to read openpyxl documents, and
1. 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.

```xml
<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_test.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
1. Filtering and grouping
1. Auto column width (the current implement is not good enough)
1. Calculated cell
1. Auto number, date and text detection
1. Spend more time on openpyxl document (yes unfortunately, I haven't got enough time)
1. 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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hkalex/jinja-excel-template",
    "name": "jinja-excel-template",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10,<4.0",
    "maintainer_email": "",
    "keywords": "jinja,excel,template,engine,xlsx,multi-sheet,multiple sheets,dynamic sheets",
    "author": "AlexYeung",
    "author_email": "hkalex@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/bb/aa/c5d6e1353dfefbc08efb251a3edf732c2a6d70ffcf2f84e0981fad63637e/jinja_excel_template-1.0.4.tar.gz",
    "platform": null,
    "description": "# Jinja Excel Template Engine\n\nThis package can handle some Excel reporting requirements.\n\nIt contains:\n\n1. Dynamic sheets based on the data\n2. Images are inside the Excel file,\n3. 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.),\n4. Printing header setting,\n5. Basic charts\n\n\nThis 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.\n\n\nThis package will suitable for you for the following scenarios:\n1. if you have XML knowledge and know how to read openpyxl documents, and\n1. if you have Jinja2 knowledge\n\n\n\n# Concept\nExcel templating is always complicated and normal Excel file does not support them. We have to use an intermediate file named ExcelXML.\n\nData + Jinja Template ---(Jinja Engine)---> ExcelXML ---(Excel Generator)---> Excel\n\nWith 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.\n\nThe ExcelXML has a specific format, so the Excel Generator can read it and draw the Excel.\n\nHere is an example of the ExcelXML.\n\n```xml\n<Excel>\n    <sheet sheetName=\"myFirstSheet\" print_area=\"A1:L10\" print_header=\"1:3\">\n        <row> <!-- first row -->\n            <cell value=\"A1\" />\n            <cell value=\"B1\" />\n            <cell value=\"C1\" />\n        </row>\n        <row /> <!-- second row, empty row -->\n        <row> <!-- third row -->\n            <cell value=\"A3\" />\n            <cell value=\"B3\" />\n            <cell value=\"C3\" />\n        </row>\n    </sheet>\n    <sheet sheetName=\"mySecondSheet\" print_area=\"A1:L10\" print_header=\"1:3\">\n        <row> <!-- first row -->\n            <cell value=\"A1\" />\n            <cell value=\"B1\" />\n            <cell value=\"C1\" />\n        </row>\n        <row /> <!-- second row, empty row -->\n        <row> <!-- third row -->\n            <cell value=\"A3\" />\n            <cell value=\"B3\" />\n            <cell value=\"C3\" />\n        </row>\n    </sheet>\n</Excel>\n```\n\nThe Jinja template is to construct the ExcelXML with your own data pipeline.\n\nWhy did I chose XML not JSON? JSON is too messy to representing meta data and attributes, so I chose XML.\n\n\n# Sample\nPlease check the `tests/countries_test.py`. It shows the raw data and group countires by region and display countries in multiple sheets. It also contains some basic diagrams.\n\nIf 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.\n\n\n# TODO list\n1. Filtering and grouping\n1. Auto column width (the current implement is not good enough)\n1. Calculated cell\n1. Auto number, date and text detection\n1. Spend more time on openpyxl document (yes unfortunately, I haven't got enough time)\n1. Pivot table?? (not sure the use case about it, put it in low priority)\n\n\n# About me\nI 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.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Jinja based Excel Template support multiple sheets",
    "version": "1.0.4",
    "project_urls": {
        "Homepage": "https://github.com/hkalex/jinja-excel-template",
        "Repository": "https://github.com/hkalex/jinja-excel-template"
    },
    "split_keywords": [
        "jinja",
        "excel",
        "template",
        "engine",
        "xlsx",
        "multi-sheet",
        "multiple sheets",
        "dynamic sheets"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a62b5cd73a7f6045044ce02e40b48ad17312e618118146a21c0be1ebe997fd27",
                "md5": "3ec12ed6f52c93ed472363ed1fa2b5ba",
                "sha256": "15003c4f5a336a56ae81eb9a94a6fc8dfacfff1b73428889fd28f74e3fe8c4b2"
            },
            "downloads": -1,
            "filename": "jinja_excel_template-1.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3ec12ed6f52c93ed472363ed1fa2b5ba",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10,<4.0",
            "size": 15986,
            "upload_time": "2023-09-25T01:42:17",
            "upload_time_iso_8601": "2023-09-25T01:42:17.239396Z",
            "url": "https://files.pythonhosted.org/packages/a6/2b/5cd73a7f6045044ce02e40b48ad17312e618118146a21c0be1ebe997fd27/jinja_excel_template-1.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bbaac5d6e1353dfefbc08efb251a3edf732c2a6d70ffcf2f84e0981fad63637e",
                "md5": "53e39d01d36df7e425af5e79325cf532",
                "sha256": "469a9d24f7f626a575f28ae8efe4757e13cef18014d00ae03ec807694478cb8a"
            },
            "downloads": -1,
            "filename": "jinja_excel_template-1.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "53e39d01d36df7e425af5e79325cf532",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10,<4.0",
            "size": 10015,
            "upload_time": "2023-09-25T01:42:18",
            "upload_time_iso_8601": "2023-09-25T01:42:18.977553Z",
            "url": "https://files.pythonhosted.org/packages/bb/aa/c5d6e1353dfefbc08efb251a3edf732c2a6d70ffcf2f84e0981fad63637e/jinja_excel_template-1.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-25 01:42:18",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hkalex",
    "github_project": "jinja-excel-template",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "jinja-excel-template"
}
        
Elapsed time: 0.26690s