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:
objectExports 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.
- export() IO[source]¶
Exports the sheets as an XLSX file.
- Returns:
The binary representation of the exported workbook.
- Return type:
- 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
- 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:
- Returns:
Status code of the write operation.
- Return type:
- 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:
- Returns:
True if successful, False otherwise.
- Return type:
- 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.
- 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:
- Returns:
True if successful, False otherwise.
- Return type:
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:
objectRepresents 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.
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:
objectRepresents a row in a spreadsheet.
- Variables:
- __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.
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:
objectRepresents a column in a spreadsheet.
- Variables:
- __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.
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:
objectRepresents 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.