Skip to main content

A Rust-powered Python library for Excel file management and data manipulation

Project description

Easy Excel Management

A Rust-powered Python module for efficient Excel file manipulation.

  • Filling: Fill an existing sheet of an existing Excel file with data based on headers that are not necessarily in the first row of the sheet. Can handle Pandas, Polars and Dict of Lists. List of lists is also supported, provided the column names are provided too. Can handle overwriting existing data. Can skip nulls. Can handle strict matching of column names.

  • Copying: Copy a range of cells from one sheet of an Excel file to a sheet in another Excel file. Can handle transposing the range.

  • Aggregating: Aggregate a range of cells from one sheet to another. Can handle summing, counting, averaging per row or column.

Installation

Install the module using pip or your favorite package manager:

   pip install ez-excel-mgt

Usage

Filling an existing sheet in an Excel file

Let's assume test.xls contains a sheet "Example" with with a few rows and columns. Let's assume the column names are contained in the third row.

Data can be provided in a Pandas, Polars, Dict of Lists or List of Lists (with column names specified in another argument).

Options

  • column: List of column names to use with a list of lists. This is optional if your DataFrame already has columns (Pandas, Polars or Dict).

  • overwrite: If True, existing data will be overwritten. Default is False.

  • skip_nulls: If True, null values in the data will be skipped. Default is False, which results in blanking cells for null values.

  • strict: If True, enforces strict matching: all column names must match exactly.

Example

from typing import List, Dict, Any
from pathlib import Path

import pandas as pd
import polars as pl
import openpyxl
from ez_excel_mgt import ExcelTemplate

# Assuming a template exists as template.xlsx with a sheet named "Example" and headers in row 3
template = ExcelTemplate("template.xlsx")
template.goto_sheet("Example")
template.set_header_location((3, 1)) # Header in row 3, column A
# template.set_header_location('A3') works as well

# Assuming that headers are in row 3, with 'Name' in column A, 'Age' in column B, 'Gender' in column C
pandas_df = pd.DataFrame({
    "Name": ["Anatole", "Erica", "Jules"],
    "Age": [85, 15, 95]
})

# Fill the sheet with the Pandas DataFrame and get rid of existing data (overwrite=True)
template.fill_with(pandas_df, overwrite=True)

# Create a Polars DataFrame
polars_df = pl.DataFrame({
    "Name": ["Philippe", "Paul"],
    "Age": [45, None],
    "Gender": ["M", "M"]
})

# Fill the sheet with the Polars DataFrame at the end of the sheet
template.fill_with(polars_df, strict=True) # strict=True to enforce strict (one to one)matching of headers (template <-> data)

# Create a dictionary with the data to be written to the Excel file
dict_df = {
    "Name": ["Michel", "Amelie"],
    "Age": [35, 45],
    "Gender": ["M", "F"],
    "City": ["Paris", "London"]
}

template.fill_with(dict_df)

# Create a list of dictionaries with the data to be written to the Excel file
# Column names must be provided separately
columns = ["Age", "Gender", "City"]
# skip_null allows to skip None values, which combined with overwrite enables filling gaps or replacing specific values like a mask
list_df = [
    [None, None, None, None, None, None, None, 55, None, None],
    [None, None, None, "M", "F", "M", None, None, None, None],
    [None, None, None, "Brussels", "Madrid", "Berlin", "Lisbon", "Montreal", None, None]
]

template.fill_with(list_df, columns=columns, skip_null=True, overwrite=True)

Copying a range of cells from one file/sheet to another file/sheet

Let's assume test.xls contains a sheet "Example" with with a few rows and columns. Let's assume the column names are contained in the first row.

Options

  • transpose: If True, the range is transposed.

Example

from ez_excel_mgt import ExcelTemplate

# Assuming template.xlsx exists, with a sheet named "Example"
template = ExcelTemplate("template.xlsx")
template.goto_sheet("Example")
template.goto_cell((2, 1))

# Assuming that a file source.xlsx exists, with a sheet named "Source"
template.copy_range_from("source.xlsx", "Source", ((2, 1), (51, 4)))

Aggregating a range of cells from one file/sheet to copying the result intoanother file/sheet

Only works with numbers! Can handle summing, counting, averaging per row or column.

Let's assume test.xls contains a sheet "Example" with with a few rows and columns. Let's assume the column names are contained in the first row.

Example

from ez_excel_mgt import ExcelTemplate

# Assuming template.xlsx exists, with a sheet named "Example"
template = ExcelTemplate("template.xlsx")
template.goto_sheet("Example")
template.goto_cell((2, 1))

# Assuming that a file source.xlsx exists, with a sheet named "Source"
template.aggregate_range_from("source.xlsx", "Source", ((2, 1), (51, 4)), "sum", "row") # Aggregation can be made by row or column

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

ez_excel_mgt-1.0.26.tar.gz (46.4 kB view details)

Uploaded Source

Built Distributions

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

ez_excel_mgt-1.0.26-cp312-cp312-win_amd64.whl (5.5 MB view details)

Uploaded CPython 3.12Windows x86-64

ez_excel_mgt-1.0.26-cp312-cp312-manylinux_2_34_x86_64.whl (6.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

ez_excel_mgt-1.0.26-cp312-cp312-macosx_11_0_arm64.whl (5.4 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

ez_excel_mgt-1.0.26-cp311-cp311-win_amd64.whl (5.5 MB view details)

Uploaded CPython 3.11Windows x86-64

ez_excel_mgt-1.0.26-cp311-cp311-manylinux_2_34_x86_64.whl (6.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

ez_excel_mgt-1.0.26-cp311-cp311-macosx_11_0_arm64.whl (5.4 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

ez_excel_mgt-1.0.26-cp310-cp310-win_amd64.whl (5.5 MB view details)

Uploaded CPython 3.10Windows x86-64

ez_excel_mgt-1.0.26-cp310-cp310-manylinux_2_34_x86_64.whl (6.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

ez_excel_mgt-1.0.26-cp310-cp310-macosx_11_0_arm64.whl (5.4 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file ez_excel_mgt-1.0.26.tar.gz.

File metadata

  • Download URL: ez_excel_mgt-1.0.26.tar.gz
  • Upload date:
  • Size: 46.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.6

File hashes

Hashes for ez_excel_mgt-1.0.26.tar.gz
Algorithm Hash digest
SHA256 a87844151c54470f6c1ac67b4a6433e70f5f692ea7c5d755fc3be15c40bafce1
MD5 69da1ff315fa8af7a554410c366c71fd
BLAKE2b-256 88e84336fd752352bc42a796013830ec36cbabd310c79fd927d2f1e63c5a883a

See more details on using hashes here.

File details

Details for the file ez_excel_mgt-1.0.26-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for ez_excel_mgt-1.0.26-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 556a354e3adea12015a0392dda7ffc623661676388970d8e17303eeb09dcc9f1
MD5 25f7cc6a9fd97f0fbf1023a28518f801
BLAKE2b-256 bfc63d47f3c708d83bfa69bd0b4f334974d05c9561008a3ed401a79d305bcf82

See more details on using hashes here.

File details

Details for the file ez_excel_mgt-1.0.26-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for ez_excel_mgt-1.0.26-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 a90f45a42ca91a6161984bd9eb8cfb02bf7bc01e94be5c7ed8897cb94536aefe
MD5 46ddbe7cb3a05524f622aebabaab1d2c
BLAKE2b-256 7d08ce24b6115bc8fe2c139392303569765ee7ad0f176624c157397bc397d01a

See more details on using hashes here.

File details

Details for the file ez_excel_mgt-1.0.26-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ez_excel_mgt-1.0.26-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ca4c6c13f5d467db5cd9df16b7871f9d06e5b10cc15eac71b697eb7a4878b89d
MD5 489154db1b6af45e4de691d9e08fad83
BLAKE2b-256 1f6c35f1fe23a87f6b56ea935cb28cdb3c9859f5d106ada7db07494f337497b1

See more details on using hashes here.

File details

Details for the file ez_excel_mgt-1.0.26-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for ez_excel_mgt-1.0.26-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 86509b2bab784d6f77ed2dbbc257e015bde7c3faa6758d33a4fd280589f73c53
MD5 e343de1aabd0613bfc39523b8fea9898
BLAKE2b-256 89dd885d29fc2333e139e3fb90a94d257041567677965b4d701f983758c5caf4

See more details on using hashes here.

File details

Details for the file ez_excel_mgt-1.0.26-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for ez_excel_mgt-1.0.26-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 4edad1f73d75370aa589e0f52b6652d670b17977326d4e44f17e98c21f2b3382
MD5 73c61079ad66dca75bc0b0041e0e2438
BLAKE2b-256 cc7f9095ba755aff3d995ca3d5377f8fb91a915748c481e06ba314b10f33d7c1

See more details on using hashes here.

File details

Details for the file ez_excel_mgt-1.0.26-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ez_excel_mgt-1.0.26-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 86cef37818293df1e89349df031683783164cd4e2e43ad4aa12c003698ce5837
MD5 8fc5db23866bdb3a32f420c3766a6401
BLAKE2b-256 79e67fcdc934d523e2a9dd24d356bbfa6f332ff3bf1e392e68af154f75becbb9

See more details on using hashes here.

File details

Details for the file ez_excel_mgt-1.0.26-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for ez_excel_mgt-1.0.26-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 19abae6023b492b4304796483acb9b0a1ddc578fe625c058ed466327b5ef1637
MD5 01e19703ea6673b0a60aeada2f271ea8
BLAKE2b-256 3c6d8a8d775f001deed320a14a9c97974bd51f83a1fba9f4aa5c360ebe4d2c05

See more details on using hashes here.

File details

Details for the file ez_excel_mgt-1.0.26-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for ez_excel_mgt-1.0.26-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 8bb16e193b71f4bab6f32704dc234719f665ec33a3e81393e1db9441a2463728
MD5 de5e10a9fe5026d4b2f1cad0bff1a07e
BLAKE2b-256 27710344e720bacbd98290b4a0d094a9653e6fc97f76e76c408de3f18a4a83a3

See more details on using hashes here.

File details

Details for the file ez_excel_mgt-1.0.26-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ez_excel_mgt-1.0.26-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1cfdb7b361c5cbc442a931073d503b227164f9ff6115a372dc2281760c5de6af
MD5 e26e7b1ee695c411189b6538c3b73d76
BLAKE2b-256 81f2ffe5972edb450ca8a9ee3460defb7fdada37745a971ad79b66792f14d813

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