Skip to content

Parser

omniread.xlsx.parser

Summary

XLSX parser implementations for OmniRead.

This module provides a concrete, generic parser for Office Open XML spreadsheets. It exposes workbook sheets as lists of string rows so downstream consumers can interpret tabular content without depending on openpyxl directly.

The parser is intentionally statement-agnostic: it performs no header detection or column interpretation beyond basic cell normalization.

Classes

XlsxParser

1
2
3
4
5
6
XlsxParser(
    content: Content,
    *,
    data_only: bool = True,
    read_only: bool = True
)

Bases: XlsxParserBase[list[list[str]]]

Generic xlsx parser producing string rows from a worksheet.

Notes

Responsibilities:

1
2
3
4
- Lazily load the workbook owned by the parser's content.
- Normalize cells (including dates and numeric values) into
  deterministic string representations.
- Expose sheet discovery and row extraction helpers.

Constraints:

1
2
3
- Cells are rendered with ``str(value)`` after trimming; date and
  datetime values are rendered in ISO format. Consumers requiring
  locale-specific formatting must convert on their side.

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
sheet_names property
sheet_names: list[str]

Names of all worksheets contained in the workbook.

supported_types class-attribute instance-attribute
supported_types = {XLSX}

Set of content types supported by this parser (XLSX only).

workbook property
workbook: Workbook

The lazily loaded workbook backing this parser's content.

Functions
parse
parse() -> list[list[str]]

Parse the first worksheet into normalized string rows.

Returns:

Type Description
list[list[str]]

List[List[str]]: Rows of the default (first) worksheet.

rows
1
2
3
4
5
rows(
    sheet: int | str | None = None,
    *,
    skip_empty: bool = True
) -> list[list[str]]

Extract normalized string rows from a worksheet.

Parameters:

Name Type Description Default
sheet Optional[Union[int, str]]

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
supports() -> bool

Check whether this parser supports the content's type.

Returns:

Name Type Description
bool bool

True if the content type is supported; False otherwise.