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.3.tar.gz
.
File metadata
- Download URL: ez_excel_mgt-1.0.3.tar.gz
- Upload date:
- Size: 121.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f074c417165473f02ab83da209d255af93fa077ff0bc927f8b7e19c98265f241 |
|
MD5 | 3c97db260b05cd09fa3f61cfb0301f17 |
|
BLAKE2b-256 | 291a94c1bb40b65750c52e891739046b7fa5f7b0145b8daf405d6a69b6915da2 |
File details
Details for the file ez_excel_mgt-1.0.3-pp310-pypy310_pp73-macosx_11_0_arm64.whl
.
File metadata
- Download URL: ez_excel_mgt-1.0.3-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 | f8768c9c70d5ab77fd4617323fdcc7a73555911c4b56d8631df5cd5a2a9795f3 |
|
MD5 | 298dad9d49023a79d14c6f30e36358b1 |
|
BLAKE2b-256 | eae609c02f275fb7ae740c7e17761a249c98087625c94986bbc87f66b6fc53e6 |
File details
Details for the file ez_excel_mgt-1.0.3-pp39-pypy39_pp73-macosx_11_0_arm64.whl
.
File metadata
- Download URL: ez_excel_mgt-1.0.3-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 | a465ba1a20f8ad11dc0dd455eafe2f48e00f9d0852535835655e6200ac01b318 |
|
MD5 | 58bc175984490dd33c078e9040c3ef07 |
|
BLAKE2b-256 | 1ef607dbc3abf46671be620d781e814b84a78102c4caf5bffe6927a05f420dca |
File details
Details for the file ez_excel_mgt-1.0.3-pp38-pypy38_pp73-macosx_11_0_arm64.whl
.
File metadata
- Download URL: ez_excel_mgt-1.0.3-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 | e149329edef68e6148cbd88add74a7173badad1b8b19db04873821f2945fda53 |
|
MD5 | 86a6ecc3a28be9e05691c63fca7053f5 |
|
BLAKE2b-256 | 4b298cda409576d1b3edb2eb38bc360a4cae5359e8b0273fabc8a26d83af31a7 |
File details
Details for the file ez_excel_mgt-1.0.3-cp312-cp312-macosx_11_0_arm64.whl
.
File metadata
- Download URL: ez_excel_mgt-1.0.3-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 | 944e5e70eba28571456a13f083f35e02ab87af64b3065488580da57a1a553667 |
|
MD5 | 1b6c882ce8572f1a9622d6e59a4b6e64 |
|
BLAKE2b-256 | 85fd84f544e4f1cf475a20672e90dad4810fab2d0bfb9ea2dd099d2754d4da29 |
File details
Details for the file ez_excel_mgt-1.0.3-cp311-cp311-macosx_11_0_arm64.whl
.
File metadata
- Download URL: ez_excel_mgt-1.0.3-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 | 2691d3f726c458c5cc58b6011f026f29fce5237b293e416f30979c14476f245a |
|
MD5 | 4cc10c7a6945eaece12daf1095daad8d |
|
BLAKE2b-256 | 7dfde87d4cf1657438f3cb823c16de6d87d41a5812f5ebf1963821660f276b5a |
File details
Details for the file ez_excel_mgt-1.0.3-cp310-cp310-macosx_11_0_arm64.whl
.
File metadata
- Download URL: ez_excel_mgt-1.0.3-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 | 79c24471d0de953b76699b05864adff576b71c61ce82249834580ece6601b578 |
|
MD5 | 9891d1dfca373324e7033ec24f7903ba |
|
BLAKE2b-256 | 10753d26a8c9aab5dd76377c46c3be50607ae9a4f55866195854b34509681382 |