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 |
| row_offset | int | 0 | Row offset for numbering |
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 |
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.0.tar.gz
(26.0 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.0.tar.gz.
File metadata
- Download URL: xlsx2dict-0.1.0.tar.gz
- Upload date:
- Size: 26.0 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 |
cd46ad49a4c8dd6b8856c51612352db728c2b3679e30042d010dfd4ff9572d39
|
|
| MD5 |
105ab52ad38de67fd095d1f3989badb7
|
|
| BLAKE2b-256 |
9ea70e23af9e2630228920d74183a2a30b2f472f9259b37d3d9327c89c30b8f5
|
File details
Details for the file xlsx2dict-0.1.0-py3-none-any.whl.
File metadata
- Download URL: xlsx2dict-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.4 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 |
fcb27a5ac0b0776f0bfba0d72a5eb32e7a0c37020256e0c1cc219810968f4cf8
|
|
| MD5 |
0b663477c5fb8821b0ceb1db0ef1ad20
|
|
| BLAKE2b-256 |
15968de1bc455144386fcb2fe09ab42071511113c434cb1e217f07e2e9bbe765
|