# Easy generate excel
An easy way to create an excel file with data
# Overview
```python
from easy_generate_excel import ExcelWorkBook, Sheet
```
### Sheet
Sheet config class
###### Parameters
| Name | Required | Default | Type | Description |
| -------------------------- | -------- | ---------- | ------------------------------- | --------------------------------------------------------- |
| name | True | - | str | Sheet name |
| headers | True | - | list | Headers list |
| data | True | | list[list] | Data list. Data will be read by data[row_idx][col_idx] |
| bold_header | False | True | bool | Need bold header |
| auto_filter | False | True | bool | Need enable auto filter in headers |
| center_cols_indexes | False | all | Literal['all'], list[int], None | Cols indexes of data cols which will be center |
| center_headers_indexes | False | all | Literal['all'], list[int], None | Cols indexes of headers cols which will be center |
| not_center_cols_indexes | False | None | Literal['all'], list[int], None | Cols indexes of data cols which will ``NOT`` be center |
| not_center_headers_indexes | False | None | Literal['all'], list[int], None | Cols indexes of headers cols which will ``NOT`` be center |
| cell_expansion | False | int, float | 1.2 | The percentage by which the cell width will be increased |
| min_cell_width | False | int | 9 | Min cell width (Excel default 9) |
#####
### ExcelWorkBook
The main class for generating excel
###### Parameters
| Name | Required | Default | Type | Description |
| ------ | -------- | ------- | ----------------------- | ---------------------- |
| sheets | True | - | List[dict], List[Sheet] | List of sheets configs |
You can pass an array of dictionaries, they will be converted to ``Sheet``
# Installation
```bash
pip install easy_generate_excel
```
```python
from easy_generate_excel import ExcelWorkBook, Sheet
```
# Example
```python
from easy_generate_excel import ExcelWorkBook, Sheet
from io import BytesIO
from openpyxl import Workbook
sh = Sheet(
name='Sheet 1',
headers=[
'Test header 1',
'Test header 2',
'Test header 3',
'Test header 4',
'Test header 5',
'Test header 6',
],
data=[
['Data 1', 'Data 2', 'Data 3', 'Data 4', 'Data 5', 'Data 6'],
['Data 7', 'Data 8', 'Data 9', 'Data 10', 'Data 11', 'Data 12'],
['Data 13', 'Data 14', 'Data 15', 'Data 16', 'Data 17', 'Data 18'],
['Data 19', 'Data 20', 'Data 21', 'Data 22', 'Data 23', 'Data 24'],
],
# NOT REQUIRED
bold_header=True,
auto_filter=True,
center_cols_indexes='all',
center_headers_indexes='all',
not_center_cols_indexes=None,
not_center_headers_indexes=None,
cell_expansion=1.2,
min_cell_width=9,
)
sh2 = Sheet(
name='Sheet 2',
headers=[
'Test header 1',
'Test header 2',
'Test header 3',
],
data=[
['Data 1', 'Data 2', 'Data 3'],
['Data 4', 'Data 5', 'Data 6'],
['Data 7', 'Data 8', 'Data 9',],
['Data 10', 'Data 11', 'Data 12'],
['Data 13', 'Data 14', 'Data 15',],
['Data 16', 'Data 17', 'Data 18'],
['Data 19', 'Data 20', 'Data 21',],
['Data 22', 'Data 23', 'Data 24'],
],
# NOT REQUIRED
bold_header=True,
auto_filter=True,
center_cols_indexes='all',
center_headers_indexes='all',
not_center_cols_indexes=None,
not_center_headers_indexes=None,
cell_expansion=1.2,
min_cell_width=9,
)
workbook_factory = ExcelWorkBook(sheets=[sh, sh2])
# Return BytesIO
output_bytes: BytesIO = workbook_factory.create(return_bytes=True)
with open('test_file.xlsx', 'wb') as fp:
fp.write(output_bytes.getvalue())
# Return workbook
output_workbook: Workbook = workbook_factory.create()
output_workbook.save('test_file.xlsx')
# Save file
output_filepath: str = workbook_factory.create_file(
output_name='test_file',
output_path=''
)
```
Raw data
{
"_id": null,
"home_page": "https://github.com/y0gurt-dv/Easy-generate-excel",
"name": "easy-generate-excel",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "excel,generators,easy",
"author": "Daniil y0gur-dv",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/ab/b5/a3b2c05b9740510ccb19932d1fa17f7191c41058b757c0953042f3a3656a/easy_generate_excel-0.0.5.tar.gz",
"platform": null,
"description": "# Easy generate excel\r\n\r\nAn easy way to create an excel file with data\r\n\r\n# Overview\r\n\r\n```python\r\nfrom easy_generate_excel import ExcelWorkBook, Sheet\r\n```\r\n\r\n### Sheet\r\n\r\nSheet config class\r\n\r\n###### Parameters\r\n\r\n| Name | Required | Default | Type | Description |\r\n| -------------------------- | -------- | ---------- | ------------------------------- | --------------------------------------------------------- |\r\n| name | True | - | str | Sheet name |\r\n| headers | True | - | list | Headers list |\r\n| data | True | | list[list] | Data list. Data will be read by data[row_idx][col_idx] |\r\n| bold_header | False | True | bool | Need bold header |\r\n| auto_filter | False | True | bool | Need enable auto filter in headers |\r\n| center_cols_indexes | False | all | Literal['all'], list[int], None | Cols indexes of data cols which will be center |\r\n| center_headers_indexes | False | all | Literal['all'], list[int], None | Cols indexes of headers cols which will be center |\r\n| not_center_cols_indexes | False | None | Literal['all'], list[int], None | Cols indexes of data cols which will ``NOT`` be center |\r\n| not_center_headers_indexes | False | None | Literal['all'], list[int], None | Cols indexes of headers cols which will ``NOT`` be center |\r\n| cell_expansion | False | int, float | 1.2 | The percentage by which the cell width will be increased |\r\n| min_cell_width | False | int | 9 | Min cell width (Excel default 9) |\r\n\r\n##### \r\n\r\n### ExcelWorkBook\r\n\r\nThe main class for generating excel\r\n\r\n###### Parameters\r\n\r\n| Name | Required | Default | Type | Description |\r\n| ------ | -------- | ------- | ----------------------- | ---------------------- |\r\n| sheets | True | - | List[dict], List[Sheet] | List of sheets configs |\r\n\r\nYou can pass an array of dictionaries, they will be converted to ``Sheet``\r\n\r\n\r\n\r\n\r\n\r\n# Installation\r\n\r\n```bash\r\npip install easy_generate_excel\r\n```\r\n\r\n```python\r\nfrom easy_generate_excel import ExcelWorkBook, Sheet\r\n```\r\n\r\n\r\n\r\n# Example\r\n\r\n```python\r\nfrom easy_generate_excel import ExcelWorkBook, Sheet\r\nfrom io import BytesIO\r\nfrom openpyxl import Workbook\r\n\r\nsh = Sheet(\r\n name='Sheet 1',\r\n headers=[\r\n 'Test header 1',\r\n 'Test header 2',\r\n 'Test header 3',\r\n 'Test header 4',\r\n 'Test header 5',\r\n 'Test header 6',\r\n ],\r\n data=[\r\n ['Data 1', 'Data 2', 'Data 3', 'Data 4', 'Data 5', 'Data 6'],\r\n ['Data 7', 'Data 8', 'Data 9', 'Data 10', 'Data 11', 'Data 12'],\r\n ['Data 13', 'Data 14', 'Data 15', 'Data 16', 'Data 17', 'Data 18'],\r\n ['Data 19', 'Data 20', 'Data 21', 'Data 22', 'Data 23', 'Data 24'],\r\n ],\r\n # NOT REQUIRED\r\n bold_header=True,\r\n auto_filter=True,\r\n center_cols_indexes='all',\r\n center_headers_indexes='all',\r\n not_center_cols_indexes=None,\r\n not_center_headers_indexes=None,\r\n cell_expansion=1.2,\r\n min_cell_width=9,\r\n)\r\nsh2 = Sheet(\r\n name='Sheet 2',\r\n headers=[\r\n 'Test header 1',\r\n 'Test header 2',\r\n 'Test header 3',\r\n ],\r\n data=[\r\n ['Data 1', 'Data 2', 'Data 3'],\r\n ['Data 4', 'Data 5', 'Data 6'],\r\n ['Data 7', 'Data 8', 'Data 9',],\r\n ['Data 10', 'Data 11', 'Data 12'],\r\n ['Data 13', 'Data 14', 'Data 15',],\r\n ['Data 16', 'Data 17', 'Data 18'],\r\n ['Data 19', 'Data 20', 'Data 21',],\r\n ['Data 22', 'Data 23', 'Data 24'],\r\n ],\r\n # NOT REQUIRED\r\n bold_header=True,\r\n auto_filter=True,\r\n center_cols_indexes='all',\r\n center_headers_indexes='all',\r\n not_center_cols_indexes=None,\r\n not_center_headers_indexes=None,\r\n cell_expansion=1.2,\r\n min_cell_width=9,\r\n)\r\n\r\nworkbook_factory = ExcelWorkBook(sheets=[sh, sh2])\r\n\r\n# Return BytesIO\r\noutput_bytes: BytesIO = workbook_factory.create(return_bytes=True)\r\nwith open('test_file.xlsx', 'wb') as fp:\r\n fp.write(output_bytes.getvalue())\r\n\r\n# Return workbook\r\noutput_workbook: Workbook = workbook_factory.create()\r\noutput_workbook.save('test_file.xlsx')\r\n\r\n# Save file\r\noutput_filepath: str = workbook_factory.create_file(\r\n output_name='test_file',\r\n output_path=''\r\n)\r\n\r\n```\r\n\r\n\r\n\r\n\r\n",
"bugtrack_url": null,
"license": "",
"summary": "Easy generate excel files",
"version": "0.0.5",
"split_keywords": [
"excel",
"generators",
"easy"
],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "fd93b6ff3276250c7cfd980686b38417",
"sha256": "428bcf53c8f6ff1a306adfcb756d04a7f0a7be9bcfeb30f312b5c43116acf8d2"
},
"downloads": -1,
"filename": "easy_generate_excel-0.0.5.tar.gz",
"has_sig": false,
"md5_digest": "fd93b6ff3276250c7cfd980686b38417",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 5593,
"upload_time": "2022-12-05T11:15:43",
"upload_time_iso_8601": "2022-12-05T11:15:43.562871Z",
"url": "https://files.pythonhosted.org/packages/ab/b5/a3b2c05b9740510ccb19932d1fa17f7191c41058b757c0953042f3a3656a/easy_generate_excel-0.0.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-12-05 11:15:43",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "y0gurt-dv",
"github_project": "Easy-generate-excel",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "easy-generate-excel"
}