Skip to main content

Save a list as an Excel file easily.

Project description

save_as_xlsx

PyPI - Version PyPI - Python Version


Table of Contents

About

If you have some tabular data, this package gives you a trivial one-line way of saving it as an Excel (.xlsx) file. The data will be saved formatted as a Table (with a header row, filtering, sorting and nice formatting).

Just pass any iterable (list, tuple, generator...) of:

  • dictionaries
  • dataclasses
  • Pydantic model instances

Nesting of complex data types is handled.

Enums are saved as the enum member name. UUIDs as their hex representation (e.g. "5f456a18-29f0-11f1-a203-e41fd5b9abcb"). Decimal and Fraction as their float representation.

Uses the xlsxwrite package to do the actual writing.

Installation

pip install save-as-xlsx

Usage

from save_as_xlsx import SaveAsXlsx, save_as_xlsx

DATA = [
    {"a": 1, "b": "qwe"},
    {"b": "asd", "c": True},
]
OTHER_DATA = [
    {"Name": "John", "Age": 46},
    {"Name": "Jane", "Age": 42},
]

# simplest case
save_as_xlsx("file.xlsx", DATA)

# or if you want to customize the XLSX file before saving, e.g. add another sheet:
with SaveAsXlsx("file.xlsx", DATA) as saver:
    # do something with saver.workbook or saver.worksheet (see xlsxwriter)
    saver.add_sheet(OTHER_DATA)

# the data can be any iterable - tuple, generator...
SaveAsXlsx("file.xlsx", ({"num": i} for i in range(5)), auto_save=True)

# file name can be a Path
from pathlib import Path
SaveAsXlsx(Path("file.xlsx"), DATA, auto_save=True)
# saved columns: a, b, c

# you can specify the order of columns - these will be first, remaining ones after them
SaveAsXlsx("file.xlsx", DATA, column_order=("b", "c"))
# saved columns: b, c, a

# or maybe you just want some of the columns, and an empty one
SaveAsXlsx("file.xlsx", DATA, column_order=("b", "empty"), extra_columns=False)
# saved columns: b, empty

# you can also specify the sheet and/or table name
with SaveAsXlsx("file.xlsx", DATA, sheet_name="FirstSheet", table_name="FirstTable") as saver:
    saver.add_sheet(OTHER_DATA, sheet_name="AnotherSheet", table_name="AnotherTable")

# or you can do the same like this
with SaveAsXlsx("file.xlsx") as saver:
    saver.add_sheet(DATA, sheet_name="FirstSheet", table_name="FirstTable")
    saver.add_sheet(OTHER_DATA, sheet_name="AnotherSheet", table_name="AnotherTable")

License

save-as-xlsx is distributed under the terms of the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

save_as_xlsx-0.4.0.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

save_as_xlsx-0.4.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file save_as_xlsx-0.4.0.tar.gz.

File metadata

  • Download URL: save_as_xlsx-0.4.0.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.14.0 HTTPX/0.28.1

File hashes

Hashes for save_as_xlsx-0.4.0.tar.gz
Algorithm Hash digest
SHA256 c4b503ffec324c513da3cbb8568007751de3c64f89466f47e1642a9320346652
MD5 a5db83ba633280e288f24408d1899f97
BLAKE2b-256 863f363f1cc684121843dfa9497f578737518b5df1e173b09798bd54dc4ede21

See more details on using hashes here.

File details

Details for the file save_as_xlsx-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: save_as_xlsx-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.14.0 HTTPX/0.28.1

File hashes

Hashes for save_as_xlsx-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1694a24ef295639b5736eaec789c6301e7c1ea67d156a4d2ef55800fe215fadd
MD5 88279d0cf2ee92e32af58709087caae5
BLAKE2b-256 2786d953aab2cd262158b10fa7c34ced9fecf84764536c826954e09ae146ad86

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page