Xlsx
omniread.xlsx
Summary
XLSX subpackage for OmniRead.
Provides acquisition and parsing of Office Open XML spreadsheet (xlsx) content:
BaseXlsxClient: abstract backing-store client for xlsx bytes.FileSystemXlsxClient: local filesystem implementation.XlsxScraper: wraps fetched bytes into canonicalContent.XlsxParserBase: content-type-enforcing parser contract.XlsxParser: generic string-row parser built on openpyxl.
Classes
BaseXlsxClient
Bases: ABC
Abstract client responsible for retrieving spreadsheet bytes.
Retrieves bytes from a specific backing store (filesystem, S3, FTP, etc.).
Notes
Responsibilities:
1 2 3 4 | |
Functions
fetch
abstractmethod
Fetch raw xlsx bytes from the given source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source |
Any
|
Identifier of the spreadsheet location, such as a file path, object storage key, or remote reference. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
bytes
|
Raw xlsx bytes. |
Raises:
| Type | Description |
|---|---|
Exception
|
Retrieval-specific errors defined by the implementation. |
FileSystemXlsxClient
Bases: BaseXlsxClient
XLSX client that reads from the local filesystem.
Notes
Guarantees:
1 2 | |
Functions
fetch
Read an xlsx file from the local filesystem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path |
Path
|
Filesystem path to the spreadsheet file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
bytes
|
Raw xlsx bytes. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the path does not exist. |
ValueError
|
If the path exists but is not a file. |
XlsxParser
Bases: XlsxParserBase[list[list[str]]]
Generic xlsx parser producing string rows from a worksheet.
Notes
Responsibilities:
1 2 3 4 | |
Constraints:
1 2 3 | |
Initialize the parser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content |
Content
|
XLSX content to parse; its type must be supported. |
required |
data_only |
bool
|
Passed to openpyxl: when True, formula cells yield their last computed value instead of the formula string. |
True
|
read_only |
bool
|
Passed to openpyxl: streaming mode for lower memory usage. |
True
|
Attributes
supported_types
class-attribute
instance-attribute
Set of content types supported by this parser (XLSX only).
Functions
parse
Parse the first worksheet into normalized string rows.
Returns:
| Type | Description |
|---|---|
list[list[str]]
|
list[list[str]]: Rows of the default (first) worksheet. |
rows
Extract normalized string rows from a worksheet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet |
int | str | None
|
Worksheet index or title; defaults to the first worksheet. |
None
|
skip_empty |
bool
|
When True (default), rows whose cells are all blank are omitted. |
True
|
Returns:
| Type | Description |
|---|---|
list[list[str]]
|
list[list[str]]: Normalized rows; trailing blank cells are trimmed per row. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the requested sheet does not exist. |
supports
Check whether this parser supports the content's type.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the content type is supported; False otherwise. |
XlsxParserBase
Bases: BaseParser[T], Generic[T]
Base xlsx parser.
Notes
Responsibilities:
1 2 3 | |
Constraints:
1 2 | |
Initialize the parser with content to be parsed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content |
Content
|
Content instance to be parsed. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the content type is not supported by this parser. |
Attributes
supported_types
class-attribute
instance-attribute
Set of content types supported by this parser (XLSX only).
Functions
parse
abstractmethod
Parse xlsx content into a structured output.
Returns:
| Name | Type | Description |
|---|---|---|
T |
T
|
Parsed representation of type |
Raises:
| Type | Description |
|---|---|
Exception
|
Parsing-specific errors as defined by the implementation. |
supports
Check whether this parser supports the content's type.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the content type is supported; False otherwise. |
XlsxScraper
Scraper for xlsx spreadsheet documents.
Notes
Responsibilities:
1 2 3 | |
Constraints:
1 2 | |
Initialize the XLSX scraper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client |
BaseXlsxClient
|
Client responsible for retrieving raw spreadsheet bytes. |
required |
Functions
fetch
Fetch an xlsx document from the given source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source |
Any
|
Identifier of the spreadsheet source as understood by the configured client. |
required |
metadata |
Mapping[str, Any] | None
|
Optional metadata to attach to the returned content. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Content |
Content
|
A |
Raises:
| Type | Description |
|---|---|
Exception
|
Retrieval-specific errors raised by the client. |