A Python library for reading and writing Excel files, converting between xlsx and dictionaries or text.
Project description
xlsx2dict
A Python library for reading and writing Excel files, converting between xlsx and dictionaries or text.
Installation
pip install xlsx2dict
Usage
Reading sheets
from xlsx2dict import sheets
sheet_names = sheets('example.xlsx')
print(sheet_names)
Parameters
| Parameter | Type | Description |
|---|---|---|
| xlsx_file | str or Path | Path to the Excel file |
Reading data as list of lists
from xlsx2dict import read
table = read('example.xlsx', 'Sheet1')
print(table)
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| xlsx_file | str or Path | - | Path to the Excel file |
| sheet_name | str or int | - | Name or index of the sheet to read |
| remove_comment | bool | True | Whether to remove rows starting with '#' |
Reading data as dictionary
from xlsx2dict import read_dict
data = read_dict('example.xlsx', 'Sheet1')
print(data)
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| xlsx_file | str or Path | - | Path to the Excel file |
| sheet_name | str or int | None | Name or index of the sheet to read (default: first sheet) |
| strip | bool | True | Whether to strip whitespace from cell values |
| key_map | dict | None | Mapping to rename column headers |
| remove_comment | bool | True | Whether to remove rows starting with '#' |
| save_list | bool | False | Whether to save the entire row as 'list' |
| head_rows | int | 1 | Number of header rows |
Return data format
{
row_number: {header: value, ...},
...
}
Writing data
from xlsx2dict import write
table = [['A', 'B'], [1, 2], [3, 4]]
write(table, 'output.xlsx', 'Sheet1')
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| table | list | - | Data as list of lists |
| xlsx_file | str or Path | - | Path to the output Excel file |
| sheet_name | str | None | Name of the sheet (default: 'Sheet1') |
Writing dictionary data
from xlsx2dict import write_dict
data = {'Sheet1': [['A', 'B'], [1, 2]]}
write_dict('output.xlsx', data)
Parameters
| Parameter | Type | Description |
|---|---|---|
| xlsx_file | str or Path | Path to the output Excel file |
| data | dict | Dictionary with sheet names as keys |
Input data format
{
"sheet1_name": [[...], [...], ...],
"sheet2_name": [[...], [...], ...],
...
}
Converting to text
xlsx2text example.xlsx -o output.txt
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| xlsx_file | str or Path | - | Path to the Excel file |
| index | int or str | None | Index of the sheet to convert (1-based, default: all) |
| output_file | str or Path | None | Path to the output text file (default: print to console) |
License
MIT
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
xlsx2dict-0.1.1.tar.gz
(26.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xlsx2dict-0.1.1.tar.gz.
File metadata
- Download URL: xlsx2dict-0.1.1.tar.gz
- Upload date:
- Size: 26.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
639882ea268aee8369f5e1fdc2243b76775f7ec23208f139e6308dbae7a9b717
|
|
| MD5 |
321f97ac129cd451c36734a75ab727f4
|
|
| BLAKE2b-256 |
742dcf059c675c326f681d921c01b59fba6eb4c658ae6cab839371ae46b14cae
|
File details
Details for the file xlsx2dict-0.1.1-py3-none-any.whl.
File metadata
- Download URL: xlsx2dict-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef17191f3deb6ada91f960dac3ca95e4527523d4fb9a9786a69f3fa765db815b
|
|
| MD5 |
563d714d5a5d6e147ac3e63c3cb375e3
|
|
| BLAKE2b-256 |
96cf8439ec6d0ed9c5ce65bc54663d5eddc5c7b76bd4940787cfd45eb5600d2d
|