xltpl


Namexltpl JSON
Version 0.20 PyPI version JSON
download
home_pagehttps://github.com/zhangyu836/xltpl
SummaryA python module to generate xls/x files from a xls/x template
upload_time2024-02-04 06:08:44
maintainer
docs_urlNone
authorZhang Yu
requires_python
licenseMIT
keywords excel xls xlsx spreadsheet workbook template
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# 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

```shell
pip install xltpl
```

## How to use

*   To use xltpl, you need to be familiar with the [syntax of jinja2 template](https://jinja.palletsprojects.com/).
*   Get a pre-written xls/x file as the template.
*   Insert variables in the cells, such as : 

```jinja2
{{name}}
```

*   ~~Insert control statements in the notes(comments) of cells, use beforerow, beforecell or aftercell to seperate them :~~


```jinja2
beforerow{% for item in items %}
```
```jinja2
beforerow{% endfor %}
```

*   Insert control statements in the cells (**v0.9**) :

```jinja2
{%- for row in rows %}
{% set outer_loop = loop %}{% for row in rows %}
Cell
{{outer_loop.index}}{{loop.index}}
{%+ endfor%}{%+ endfor%}
```

*   Run the code
```python
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
* [pydocxtpl](https://github.com/zhangyu836/pydocxtpl)  
A python module to generate docx files from a docx template.
* [django-excel-export](https://github.com/zhangyu836/django-excel-export)  
A Django library for exporting data in xlsx, xls, docx format, utilizing xltpl and pydocxtpl, with admin integration.  
[Demo project](https://github.com/zhangyu836/django-excel-export-demo)   
[Live demo](https://tranquil-tundra-83829.herokuapp.com/) (User name: admin
Password: admin)   

* [xltpl for nodejs](https://github.com/zhangyu836/node-xlsx-template)   
CodeSandbox examples: 
[browser](https://codesandbox.io/s/xlsx-export-with-exceljs-and-xltpl-58j9g6)
[node](https://codesandbox.io/s/exceljs-template-with-xltpl-4w58xo)    
* [xltpl for java](https://github.com/zhangyu836/xltpl4java)


## Notes

### xlrd

xlrd does not extract print settings.   
[This repo](https://github.com/zhangyu836/xlrd) does. 

### xlwt

xlwt always sets the default font to 'Arial'.  
Excel measures column width units based on the default font.   
[This repo](https://github.com/zhangyu836/xlwt) does not.  



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/zhangyu836/xltpl",
    "name": "xltpl",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "Excel,xls,xlsx,spreadsheet,workbook,template",
    "author": "Zhang Yu",
    "author_email": "zhangyu836@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/84/ea/aff4eef3a8e94623bafa5d02d14a6f3c65c52ab56e673f1715f946201a52/xltpl-0.20.tar.gz",
    "platform": "Any platform",
    "description": "\n# xltpl\nA python module to generate xls/x files from a xls/x template.\n\n## How it works\n\nWhen xltpl reads a xls/x file, it creates a tree for each worksheet.  \nAnd, each tree is translated to a jinja2 template with custom tags.  \nWhen the template is rendered, jinja2 extensions of cumtom tags call corresponding tree nodes to write the xls/x file.\n\n## How to install\n\n```shell\npip install xltpl\n```\n\n## How to use\n\n*   To use xltpl, you need to be familiar with the [syntax of jinja2 template](https://jinja.palletsprojects.com/).\n*   Get a pre-written xls/x file as the template.\n*   Insert variables in the cells, such as : \n\n```jinja2\n{{name}}\n```\n\n*   ~~Insert control statements in the notes(comments) of cells, use beforerow, beforecell or aftercell to seperate them :~~\n\n\n```jinja2\nbeforerow{% for item in items %}\n```\n```jinja2\nbeforerow{% endfor %}\n```\n\n*   Insert control statements in the cells (**v0.9**) :\n\n```jinja2\n{%- for row in rows %}\n{% set outer_loop = loop %}{% for row in rows %}\nCell\n{{outer_loop.index}}{{loop.index}}\n{%+ endfor%}{%+ endfor%}\n```\n\n*   Run the code\n```python\nfrom xltpl.writerx import BookWriter\nwriter = BookWriter('tpl.xlsx')\nperson_info = {'name': u'Hello Wizard'}\nitems = ['1', '1', '1', '1', '1', '1', '1', '1', ]\nperson_info['items'] = items\npayloads = [person_info]\nwriter.render_book(payloads)\nwriter.save('result.xlsx')\n```\n\n## Supported\n* MergedCell   \n* Non-string value for a cell (use **{% xv variable %}** to specify a variable) \n* For xlsx  \nImage (use **{% img variable %}**)  \nDataValidation   \nAutoFilter\n\n\n## Related\n* [pydocxtpl](https://github.com/zhangyu836/pydocxtpl)  \nA python module to generate docx files from a docx template.\n* [django-excel-export](https://github.com/zhangyu836/django-excel-export)  \nA Django library for exporting data in xlsx, xls, docx format, utilizing xltpl and pydocxtpl, with admin integration.  \n[Demo project](https://github.com/zhangyu836/django-excel-export-demo)   \n[Live demo](https://tranquil-tundra-83829.herokuapp.com/) (User name: admin\nPassword: admin)   \n\n* [xltpl for nodejs](https://github.com/zhangyu836/node-xlsx-template)   \nCodeSandbox examples: \n[browser](https://codesandbox.io/s/xlsx-export-with-exceljs-and-xltpl-58j9g6)\n[node](https://codesandbox.io/s/exceljs-template-with-xltpl-4w58xo)    \n* [xltpl for java](https://github.com/zhangyu836/xltpl4java)\n\n\n## Notes\n\n### xlrd\n\nxlrd does not extract print settings.   \n[This repo](https://github.com/zhangyu836/xlrd) does. \n\n### xlwt\n\nxlwt always sets the default font to 'Arial'.  \nExcel measures column width units based on the default font.   \n[This repo](https://github.com/zhangyu836/xlwt) does not.  \n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A python module to generate xls/x files from a xls/x template",
    "version": "0.20",
    "project_urls": {
        "Homepage": "https://github.com/zhangyu836/xltpl"
    },
    "split_keywords": [
        "excel",
        "xls",
        "xlsx",
        "spreadsheet",
        "workbook",
        "template"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "069b81e7808a69b360dbcb7d1e089ce90c90bb2eaa8cceb1120141e407a903fd",
                "md5": "6bf9e915024f861c7643f007bb694a85",
                "sha256": "7fd9e62a7dd268bdf0ba483ec9fec5ef204f827c3348b6ccb2550ebb4276b1d8"
            },
            "downloads": -1,
            "filename": "xltpl-0.20-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6bf9e915024f861c7643f007bb694a85",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 28425,
            "upload_time": "2024-02-04T06:08:40",
            "upload_time_iso_8601": "2024-02-04T06:08:40.918361Z",
            "url": "https://files.pythonhosted.org/packages/06/9b/81e7808a69b360dbcb7d1e089ce90c90bb2eaa8cceb1120141e407a903fd/xltpl-0.20-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "84eaaff4eef3a8e94623bafa5d02d14a6f3c65c52ab56e673f1715f946201a52",
                "md5": "1c8891a1ee1fdb584514cdfec0499ebb",
                "sha256": "ff326935766db3aba7007e62d23f79f6a855e8ce6e9b8c6cf33191b4697a8f10"
            },
            "downloads": -1,
            "filename": "xltpl-0.20.tar.gz",
            "has_sig": false,
            "md5_digest": "1c8891a1ee1fdb584514cdfec0499ebb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 24380,
            "upload_time": "2024-02-04T06:08:44",
            "upload_time_iso_8601": "2024-02-04T06:08:44.164456Z",
            "url": "https://files.pythonhosted.org/packages/84/ea/aff4eef3a8e94623bafa5d02d14a6f3c65c52ab56e673f1715f946201a52/xltpl-0.20.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-04 06:08:44",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "zhangyu836",
    "github_project": "xltpl",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "xltpl"
}
        
Elapsed time: 0.19986s