Skip to main content

No project description provided

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.1.tar.gz (121.8 kB view details)

Uploaded Source

Built Distributions

ez_excel_mgt-1.0.1-pp310-pypy310_pp73-macosx_11_0_arm64.whl (5.3 MB view details)

Uploaded PyPy macOS 11.0+ ARM64

ez_excel_mgt-1.0.1-pp39-pypy39_pp73-macosx_11_0_arm64.whl (5.3 MB view details)

Uploaded PyPy macOS 11.0+ ARM64

ez_excel_mgt-1.0.1-pp38-pypy38_pp73-macosx_11_0_arm64.whl (5.3 MB view details)

Uploaded PyPy macOS 11.0+ ARM64

ez_excel_mgt-1.0.1-cp312-cp312-macosx_11_0_arm64.whl (5.3 MB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

ez_excel_mgt-1.0.1-cp311-cp311-macosx_11_0_arm64.whl (5.3 MB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

ez_excel_mgt-1.0.1-cp310-cp310-macosx_11_0_arm64.whl (5.3 MB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: ez_excel_mgt-1.0.1.tar.gz
  • Upload date:
  • Size: 121.8 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.1.tar.gz
Algorithm Hash digest
SHA256 e5bb94c902b2745d191fbd6e647d451a90415f2fc2b4cf8466956fcf1ccb2fab
MD5 12677829eb9008572b83d3701f3f49c4
BLAKE2b-256 edd965ae84b1eb887d5d6955c348418c653fc578e96acb6d8846993d44738021

See more details on using hashes here.

File details

Details for the file ez_excel_mgt-1.0.1-pp310-pypy310_pp73-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ez_excel_mgt-1.0.1-pp310-pypy310_pp73-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 301bf4d1be38e46e1db07154d50599776d7f6bc919b0eea2550160c49aede2d5
MD5 a1ee51d14e84815b80fc8f2e45b12c14
BLAKE2b-256 fb6169f5026297d161c8e257fa3e30e583381bdd48b94e9ec2db23e228261064

See more details on using hashes here.

File details

Details for the file ez_excel_mgt-1.0.1-pp39-pypy39_pp73-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ez_excel_mgt-1.0.1-pp39-pypy39_pp73-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5c262334ca78d1057ced93443a8c64823bbbdb6d56d4f11417eb624359ae6143
MD5 48aae37c44cc2751840ad2a488b6d41b
BLAKE2b-256 e56e009d96046bb9599e7ee0a669e8ea60392c529a7e3ab98361014569c5aa9b

See more details on using hashes here.

File details

Details for the file ez_excel_mgt-1.0.1-pp38-pypy38_pp73-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ez_excel_mgt-1.0.1-pp38-pypy38_pp73-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 47980e358f6c03f47e7f079cc3c2c97d93981f72241e682875a812f09534550b
MD5 de0fe6ec330c5c761180b8e2e7f401fd
BLAKE2b-256 08d1c219008f3bc9cb80a373ceecfe70471eae8a889d6795fceef43dbe23dec6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ez_excel_mgt-1.0.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 04c892e41eb5b2cfbb9eeec8bf181befaa494521a08bc4b666f9cf286cf88ef9
MD5 56700cccbe13b3c8cabbb8a463519006
BLAKE2b-256 40f258521edc4924e992659f9103f62d1841aa61b3740d5def7219029fe74e67

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ez_excel_mgt-1.0.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 91a7060e0b3146000ccc03fcbf72ad02eb2430d0693d07d8ef4ea0a99bbc6d8f
MD5 e497491042cecf4f60a99b0d6937c920
BLAKE2b-256 2b6eccc2c07e3494c164752a59a9499b1dcf068a2c9a627ca511b527135aedd1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ez_excel_mgt-1.0.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cde5e1ea8e30c9ae5ff9b6582a45f50c4c4c6b53a1940e3c4549ca8c49b92c37
MD5 21634c7f7fefea8c2cc2b27a638498a7
BLAKE2b-256 258662ce434693c1b18d2ed31cdbe8a3041c10f18e7ba8a959b887d7a99334e9

See more details on using hashes here.

Supported by

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