Extract data from Excel files
Project description
XLExtract
An abstraction layer for quickly pulling data out of Microsoft Excel Spreadsheets.
The project is currently powered by the openpyxl and pandas libraries but you don't need to know anything about those underlying libraries and they could change in the future.
Installation
xlextract can be installed via poetry with: poetry add xlextract
or via pip with: pip install xlextract
What does it do?
xlextract searches a spreadsheet for a keyword you provide and extracts nearby data.
It provides three operations:
- Right Lookup: Extract cell value to the immediate right of the keyword
- Left Lookup: Extract cell value to the immediate left of the keyword
- Bottom Lookup: Extract cell value immediateley below the keyword
- Table Lookup: Extract an entire Excel table of data adjacent to the keyword. The table is modeled as a list of dictionaries where each list item represents a row in the table and the list item is a dictionary (key/value pairs) where each item in the dictionary represents a column of the row and where the key is the column header. An example will be provided below.
How do I use it in my project?
You need four bits of information to use xlextract:
- The name of the Excel file
- The name of the sheet in the Excel file
- The keyword you want to search for
- The type of lookup you want to do (Right, Left, Bottom, or Table)
The project provides a class named XLExtract that requires the first 3 inputs above as strings.
The lookup is done via one of four class methods:
RLookup()(Right Lookup)LLookup()(Left Lookup)BLookup()(Bottom Lookup)TLookup()(Table Lookup)
Here is an example of how to import the library and create a sheet object ready for lookup:
import json # This is just to print our example table with formatting
from xlextract import XLExtract
vrf_table = XLExtract("design_document.xlsx", "Tenants", "VRF NAME")
Table Lookup Example
Assuming we have an Excel spreadsheet with a "Tenants" tab that contains a table that looks like this:
If we then do this in our Python code:
vrf_table.TLookup()
print(json.dumps(vrf_table.value, indent = 4))
We would get the following output:
[
{
"TENANT": "Prod-tn",
"VRF NAME": "Prod-VRF",
"ENABLE PREFERRED GROUP": "enabled"
},
{
"TENANT": "Prod-tn",
"VRF NAME": "Dev-VRF",
"ENABLE PREFERRED GROUP": "enabled"
}
]
CAVEATS
The source Excel spreadsheet content should be planned ahead of time to account for these operational caveats:
- Keywords on a given sheet should be unique (the first instance found is used)
- Keywords for a table must be one of the column headers (keyword defines the header row)
- Keyword columns are assumed to be required values. Any rows that do not have a value for the keyword column will be filtered out.
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 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 xlextract-0.2.4.tar.gz.
File metadata
- Download URL: xlextract-0.2.4.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.11.9 Linux/6.6.87.2-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a3dea6cdf5275e40be6020a003137ed1b865d28f8c187ce9ca9f894bc2bdb479
|
|
| MD5 |
6f94e523c41ca6bf67af9a90306f6c11
|
|
| BLAKE2b-256 |
284261ffde3742044195cb6bcc7883ff03d543a9025a246f220bcd8a1715b720
|
File details
Details for the file xlextract-0.2.4-py3-none-any.whl.
File metadata
- Download URL: xlextract-0.2.4-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.11.9 Linux/6.6.87.2-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
530e344df7d24a074ea4f518750c49bb12ecb238a3896d2fce8f3a647ce547a4
|
|
| MD5 |
9db90cec7a552b03a3234595d5226cab
|
|
| BLAKE2b-256 |
2c9e6216cce56240c90214de80acfa8c4075a7ca4b80d46eeac638d335531732
|