Easy generate excel files
Project description
Easy generate excel
An easy way to create an excel file with data
Overview
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
pip install easy_generate_excel
from easy_generate_excel import ExcelWorkBook, Sheet
Example
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=''
)
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
Close
Hashes for easy_generate_excel-0.0.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 428bcf53c8f6ff1a306adfcb756d04a7f0a7be9bcfeb30f312b5c43116acf8d2 |
|
MD5 | fd93b6ff3276250c7cfd980686b38417 |
|
BLAKE2b-256 | abb5a3b2c05b9740510ccb19932d1fa17f7191c41058b757c0953042f3a3656a |