API Reference

XlsxExporter

class exdata.exporter.XlsxExporter(*, sheets: list[Sheet], formats: dict | None = None, workbook_options: dict | None = None, buffer: IO | Path | str | None = None)[source]

Bases: object

Exports sheets to an XLSX file format.

This class handles formatting, column width settings, and workbook options for exporting sheets.

Variables:

workbook_options (dict) – Options for configuring the workbook.

__init__(*, sheets: list[Sheet], formats: dict | None = None, workbook_options: dict | None = None, buffer: IO | Path | str | None = None) None[source]

Initializes the XLSX exporter.

Parameters:
  • sheets (list[Sheet]) – The sheets to be included in the export.

  • formats (dict | None) – Formatting options for cells.

  • workbook_options (dict | None) – Workbook configuration.

  • buffer (io.IOBase | Path | str | None) – A buffer for workbook storage.

export() IO[source]

Exports the sheets as an XLSX file.

Returns:

The binary representation of the exported workbook.

Return type:

bytes

get_format(*names: str | None) Format | None[source]

Retrieves a predefined format by its name.

Parameters:

names (str | None) – The names of formats.

Returns:

The requested format, or None if names is not

provided.

Return type:

XlsxFormat | None

workbook_options: dict
write_cell(worksheet: Worksheet, row_number: int, col_number: int, cell: Cell, content_size: Size, formats: tuple[str]) int[source]

Writes a single cell to the worksheet.

Parameters:
  • worksheet (Worksheet) – The target worksheet.

  • row_number (int) – The row index where the cell is written.

  • col_number (int) – The column index where data will be written.

  • cell (Cell) – The cell object containing data and formatting.

  • content_size (Size) – The size constraints for the cell.

  • formats (tuple[str]) – Formatting options.

Returns:

Status code of the write operation.

Return type:

int

static write_column(worksheet: Worksheet, row_number: int, col_number: int, column: Column, content_size: Size, formats: tuple[str]) bool[source]

Writes a column of data into the worksheet.

Parameters:
  • worksheet (Worksheet) – The target worksheet.

  • row_number (int) – The row index where the column starts.

  • col_number (int) – The column index where data will be written.

  • column (Column) – The column object containing the data.

  • content_size (Size) – The total size of the column content.

  • formats (tuple[str]) – Formatting options.

Returns:

True if successful, False otherwise.

Return type:

bool

write_rich(worksheet: Worksheet, row_number: int, col_number: int, value: RichValue, cell_format: Format | None = None) int[source]

Writes rich text content into a cell.

Parameters:
  • worksheet (Worksheet) – The target worksheet.

  • row_number (int) – Row index for the cell.

  • col_number (int) – Column index for the cell.

  • value (RichValue) – Rich text to write.

  • cell_format (str | None) – Formatting options.

Returns:

Status code of the write operation.

Return type:

int

static write_row(worksheet: Worksheet, row_number: int, col_number: int, row: Row, content_size: Size, formats: tuple[str]) bool[source]

Writes a row of data into the worksheet.

Parameters:
  • worksheet (Worksheet) – The target worksheet.

  • row_number (int) – The row index where data will be written.

  • col_number (int) – The column index for the first cell.

  • row (Row) – The row object containing the data.

  • content_size (Size) – The total size of the row content.

  • formats (tuple[str]) – Formatting options.

Returns:

True if successful, False otherwise.

Return type:

bool

write_sheet(workbook: Workbook, sheet: Sheet) None[source]

Writes an entire sheet to the workbook.

Parameters:
  • workbook (Workbook) – The target workbook.

  • sheet (Sheet) – The sheet object containing data and settings.

Data Structures

Sheet

class exdata.struct.Sheet(*, data: Iterable[Row], name: str | None = None, format: str | None = None, column_width: dict[int, int] = <factory>, autofit_max_width: int | None | Default = <class 'exdata.struct.Default'>)[source]

Bases: object

Represents a sheet in a workbook.

Variables:
  • data (Iterable[Row]) – The rows contained in the sheet.

  • name (str | None) – The name of the sheet.

  • format (str | None) – The formatting style for the sheet.

  • column_width (dict[int, int]) – Mapping of column indices to widths.

  • autofit_max_width (int | None | Default) – Max width for auto-fit columns.

__iter__() Iterator[Row][source]

Iterates over the sheet’s rows.

Returns:

An iterator over the sheet rows.

Return type:

Iterator[Row]

autofit_max_width

alias of Default

column_width: dict[int, int]
data: Iterable[Row]
format: str | None = None
name: str | None = None

Row

class exdata.struct.Row(data: Iterable[Cell | Column | Row], heights: list[int] | None = <factory>, format: str | None = None, expand: bool = True, x_offset: int = 0, y_offset: int = 0)[source]

Bases: object

Represents a row in a spreadsheet.

Variables:
  • data (Iterable[Cell | Column | Row]) – Initial row data.

  • heights (list[int] | None) – Row heights for each item.

  • format (str | None) – The formatting style for the row.

  • expand (bool) – Whether the row expands with its parent.

  • x_offset (int) – Horizontal offset from its parent.

  • y_offset (int) – Vertical offset from its parent.

__iter__() Iterator[Cell | Row | Column][source]

Iterates over the row’s contents.

Returns:

An iterator over the row items.

Return type:

Iterator[Cell | Row | Column]

__post_init__() None[source]

Converts the data attribute to a list after initialization.

This ensures that the data attribute is always a list, regardless of the input type provided during instantiation.

data: Iterable[Cell | Column | Row]
expand: bool = True
format: str | None = None
heights: list[int] | None
property size: Size

Computes the total size of the row including offsets.

Returns:

The computed size.

Return type:

Size

x_offset: int = 0
y_offset: int = 0

Column

class exdata.struct.Column(data: Iterable[Cell | Row | Column], format: str | None = None, x_offset: int = 0, y_offset: int = 0, expand: bool = True)[source]

Bases: object

Represents a column in a spreadsheet.

Variables:
  • data (Iterable[Cell | Row | Column]) – Initial column data.

  • format (str | None) – The formatting style for the column.

  • x_offset (int) – Horizontal offset from its parent.

  • y_offset (int) – Vertical offset from its parent.

  • expand (bool) – Whether the column expands with its parent.

__iter__() Iterator[Cell | Row | Column][source]

Iterates over the column’s contents.

Returns:

An iterator over the column items.

Return type:

Iterator[Cell | Row | Column]

__post_init__() None[source]

Converts the data attribute to a list after initialization.

This ensures that the data attribute is always a list, regardless of the input type provided during instantiation.

data: Iterable[Cell | Row | Column]
expand: bool = True
format: str | None = None
property size: Size

Computes the total size of the column including offsets.

Returns:

The computed size.

Return type:

Size

x_offset: int = 0
y_offset: int = 0

Cell

class exdata.struct.Cell(value: Any, format: str | None = None, columns: int = 1, rows: int = 1, x_offset: int = 0, y_offset: int = 0, expand: bool = True)[source]

Bases: object

Represents a spreadsheet cell.

Variables:
  • value (Any) – The value stored in the cell.

  • format (str | None) – The formatting style for the cell.

  • columns (int) – The number of columns the cell spans.

  • rows (int) – The number of rows the cell spans.

  • x_offset (int) – Horizontal offset from its parent.

  • y_offset (int) – Vertical offset from its parent.

  • expand (bool) – Whether the cell expands with its parent.

columns: int = 1
expand: bool = True
format: str | None = None
rows: int = 1
property size: Size

Computes the total size of the cell including offsets.

Returns:

The total size of the cell.

Return type:

Size

value: Any
x_offset: int = 0
y_offset: int = 0

Format

class exdata.struct.Format(name: str)[source]

Bases: object

Represents a formatting style by name.

Variables:

name (str) – The name of the format.

name: str

RichValue

class exdata.struct.RichValue(value: list[Any])[source]

Bases: object

Represents rich text content, including formatting elements.

Variables:

value (list[Any]) – A list of rich text and formatting elements.

value: list[Any]

Size

class exdata.struct.Size(*, rows: int, columns: int)[source]

Bases: object

Represents the size of an element in terms of rows and columns.

Variables:
  • rows (int) – The number of rows occupied.

  • columns (int) – The number of columns occupied.

clear_offset(x_offset: int, y_offset: int) Size[source]

Removes the provided offset values from the size.

Parameters:
  • x_offset (int) – The x-axis offset.

  • y_offset (int) – The y-axis offset.

Returns:

The adjusted size without the offsets.

Return type:

Size

columns: int
rows: int

Default

class exdata.struct.Default[source]

Bases: object

Placeholder for unset attributes, when None is a valid value.