Class WriteTableColumn

class ooodev.write.table.write_table_column.WriteTableColumn(owner, idx)[source]

Bases: WriteDocPropPartial, WriteTablePropPartial, EventsPartial, LoInstPropsPartial

Represents writer table column.

Parameters:
  • owner (Any) –

  • idx (int) –

__getitem__(key)[source]

Returns the Write Table Cell. The cell must exist in the current column.

Parameters:

key (Any) – Key. can be a integer such as 2 for row index (-1 get last cell in col, -2 second last) or a string such as “A1” or a CellObj.

Raises:

IndexError – If the key is out of range.

Returns:

Table Cell Object.

Return type:

WriteTableCell

Note

If key is an integer then it is assumed to be a row index. If key is a string then it is assumed to be a cell name.

Cell names and CellObj are relative to the current column. If the current column is the first column of the table then the cell names and CellObj are the same as the parent table. If the column index is 3 then col[`A1`] is the same as table[`C1`].

No mater the column index the first cell of the column is always col[0] or col['A1'].

Example

>>> table = doc.tables[0]
>>> row = table.rows[3]
>>> cell = row["A1"] # or row[0]
>>> print(cell, cell.value)
WriteTableCell(cell_name=A4) Goldfinger
__init__(owner, idx)[source]

Constructor

Parameters:
  • owner (Any) – Owner of this instance.

  • idx (int) –

Return type:

None

__iter__()[source]

Iterates through the cells of the row.

Return type:

Generator[WriteTableCell, None, None]

add_event_observers(*args)

Adds observers that gets their trigger method called when this class trigger method is called.

Parameters:

args (EventObserver) – One or more observers to add.

Return type:

None

Note

Observers are removed automatically when they are out of scope.

get_cell_range()[source]

Gets the range of this column.

Return type:

WriteTableCellRange

get_column_data(as_floats=False, start_row_idx=0)[source]

Gets the data of the column.

Parameters:
  • as_floats (bool, optional) – If True then get all values as floats. If the cell is not a number then it is converted to 0.0. Defaults to False.

  • start_row_idx (int, optional) – Start Row Index. Zero Based. Can be negative to get from end. Defaults to 0.

Returns:

Column data. If as_floats is True then all values are floats.

Return type:

Tuple[float | str | None, …]

remove_event_observer(observer)

Removes an observer

Parameters:

observer (EventObserver) – One or more observers to add.

Returns:

True if observer has been removed; Otherwise, False.

Return type:

bool

subscribe_event(event_name, callback)

Add an event listener to current instance.

Parameters:
  • event_name (str) – Event Name.

  • callback (EventCallback) – Callback of the event listener.

Return type:

None

trigger_event(event_name, event_args)

Trigger an event on current instance.

Parameters:
  • event_name (str) – Event Name.

  • event_args (EventArgsT) – Event Args.

Return type:

None

unsubscribe_event(event_name, callback)

Remove an event listener from current instance.

Parameters:
  • event_name (str) – Event Name.

  • callback (EventCallback) – Callback of the event listener.

Return type:

None

property event_observer: EventObserver

Gets/Sets The Event Observer for this instance.

Return type:

EventObserver

property index: int

Index of this column.

Return type:

int

property lo_inst: LoInst

Lo Instance

Return type:

LoInst

property office_doc: OfficeDocumentT

Office Document.

Return type:

OfficeDocumentT

property owner: Any

Owner of this instance.

Return type:

Any

property range_obj: RangeObj

Range Object that represents this column cell range.

Return type:

RangeObj

property write_doc: WriteDoc

Write Document.

Return type:

WriteDoc

property write_table: WriteTable[Any]

Write Document.

Return type:

WriteTable[Any]