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 isFalse
. -
skip_nulls: If
True
, null values in the data will be skipped. Default isFalse
, 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
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
Built Distributions
File details
Details for the file ez_excel_mgt-1.0.4.tar.gz
.
File metadata
- Download URL: ez_excel_mgt-1.0.4.tar.gz
- Upload date:
- Size: 122.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e14ffd52c52d2f8f02858384714dfe8d95e1ebd996cb3ccd9735bcbe8b308f60 |
|
MD5 | efbb81f2236886b05b88e1a28e18928f |
|
BLAKE2b-256 | 806fa3fc82c668aa702013f724891a31d61c884316b4b8dd661c2a565ef801d2 |
File details
Details for the file ez_excel_mgt-1.0.4-pp310-pypy310_pp73-macosx_11_0_arm64.whl
.
File metadata
- Download URL: ez_excel_mgt-1.0.4-pp310-pypy310_pp73-macosx_11_0_arm64.whl
- Upload date:
- Size: 5.3 MB
- Tags: PyPy, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a0e924b609c43aa4bef48757a17673384f7e22f8c5a7da6fe2000b51854e244 |
|
MD5 | 3814e8947a8edb3dd1a1196b468dc4f3 |
|
BLAKE2b-256 | 8417da8de07596cd9750c64c173d40812e1d19b7b8b89498c508b8ea4db2376c |
File details
Details for the file ez_excel_mgt-1.0.4-pp39-pypy39_pp73-macosx_11_0_arm64.whl
.
File metadata
- Download URL: ez_excel_mgt-1.0.4-pp39-pypy39_pp73-macosx_11_0_arm64.whl
- Upload date:
- Size: 5.3 MB
- Tags: PyPy, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d09c0723b18f33837d258ad91f148e73dd153a12c69db10b1995541047534b66 |
|
MD5 | 06cea0f1218e147d3ed9770c821ac9b4 |
|
BLAKE2b-256 | 7d9cac7c28dff1692d3c171aba968370b58e3f23cdd7535f7e0af50604b581aa |
File details
Details for the file ez_excel_mgt-1.0.4-pp38-pypy38_pp73-macosx_11_0_arm64.whl
.
File metadata
- Download URL: ez_excel_mgt-1.0.4-pp38-pypy38_pp73-macosx_11_0_arm64.whl
- Upload date:
- Size: 5.3 MB
- Tags: PyPy, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5bd0a7cfc5b4b8c24e96ee2c5e2ba5c24b091075f5f18567b747b6a67af7456c |
|
MD5 | 1fc1fe7ef816b738e97bddf834020910 |
|
BLAKE2b-256 | 55bdfcad1891df180fc0765c4b8d078792b75b919667decb3112a7d4b8e011f2 |
File details
Details for the file ez_excel_mgt-1.0.4-cp312-cp312-macosx_11_0_arm64.whl
.
File metadata
- Download URL: ez_excel_mgt-1.0.4-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 5.3 MB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d52c4efe1a18b752130815be9fc14dbdda194968bfdf5db186aa7c761cd01822 |
|
MD5 | 0ab03e77074ec21675f4282aeb50926b |
|
BLAKE2b-256 | 427e30911192107589f1b33bd6e47c100877505e6b2a2ee3b20dd22e1f7257d8 |
File details
Details for the file ez_excel_mgt-1.0.4-cp311-cp311-macosx_11_0_arm64.whl
.
File metadata
- Download URL: ez_excel_mgt-1.0.4-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 5.3 MB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93d7cf27ef224ea1793405f9a41e16f4598e7064eef2e958c844dd96e576d1ba |
|
MD5 | d92cf5a88ecff64240f696b4fda8143a |
|
BLAKE2b-256 | 025b3949301a57e77d218ff5acbb212fc4a0a2fe90fb4bf5725cc90ce651aa2a |
File details
Details for the file ez_excel_mgt-1.0.4-cp310-cp310-macosx_11_0_arm64.whl
.
File metadata
- Download URL: ez_excel_mgt-1.0.4-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 5.3 MB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c202b71e34eed7fc452b2e6cdf0feaf97dcadc6218c922c56ad2b1000effd401 |
|
MD5 | 3ebb0b221ed65921c8c2835343638881 |
|
BLAKE2b-256 | 4786f28a7e3f7291b7f333c23d29ea268d37ccbd87d999b5c25c449aa155d583 |