Skip to main content

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=''
)

Metadata

Release files for easy-generate-excel 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for easy-generate-excel 0.0.5
File Size Uploaded
easy_generate_excel-0.0.5.tar.gz 5.6 kB Details

Release files / easy_generate_excel-0.0.5.tar.gz

Download URL easy_generate_excel-0.0.5.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
428bcf53c8f6ff1a306adfcb756d04a7f0a7be9bcfeb30f312b5c43116acf8d2
BLAKE2b-256 checksum
How to use checksums
abb5a3b2c05b9740510ccb19932d1fa17f7191c41058b757c0953042f3a3656a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.5

Release history Release notifications | RSS feed

This release

0.0.5 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page