Class WriteTables

class ooodev.write.table.write_tables.WriteTables(owner, component, lo_inst=None)[source]

Bases: LoInstPropsPartial, WriteDocPropPartial, TextTablesComp, QiPartial, Generic[T]

Represents writer text tables.

Contains Enumeration Access.

A table can be added to a document using a cursor.

Example

doc = WriteDoc.create_doc(loader=loader, visible=True)
tbl_data = read_table(fnm) # get the table data from a file.
cursor = doc.get_cursor()
cursor.append_para("Table of Bond Movies")
cursor.append_para('The following table comes form "bondMovies.txt"\n')

# with doc locks the controllers while the table is being added to the document.
with doc:
    cursor.add_table(table_data=tbl_data))
    cursor.end_paragraph()

my_table = doc.tables[-1] # get the last table added to the document.
cell = my_table["D3"]
# ...
__getitem__(key)[source]

Gets the table at the specified index or name.

This is short hand for get_by_index() or get_by_name().

Parameters:

key (key, str, int) – The index or name of the form. When getting by index can be a negative value to get from the end.

Returns:

The table with the specified index or name.

Return type:

WriteTable[WriteTables[T]]

See also

  • get_by_index()

  • get_by_name()

__init__(owner, component, lo_inst=None)[source]

Constructor

Parameters:
  • owner (T) – Owner of this component.

  • component (XText) – UNO object that supports com.sun.star.text.Text service.

  • lo_inst (LoInst, optional) – Lo instance. Defaults to None.

Return type:

None

__next__()[source]

Gets the next element.

Returns:

Next element.

Return type:

WriteTable[WriteTables[T]]

get_by_index(idx)[source]

Gets the element at the specified index.

Parameters:

idx (int) – The Zero-based index of the element. Idx can be a negative value to index from the end of the list. For example, -1 will return the last element.

Returns:

The element at the specified index.

Return type:

WriteTable[WriteTables[T]]

get_by_name(name)[source]

Gets the element with the specified name.

Parameters:

name (str) – The name of the element.

Raises:

MissingNameError – If form is not found.

Returns:

The element with the specified name.

Return type:

WriteTable[WriteTables[T]]

get_count()

Gets the number of elements contained in the container.

Returns:

The number of elements.

Return type:

int

get_element_names()

Gets the names of all elements contained in the container.

Returns:

The names of all elements.

Return type:

tuple[str, …]

get_element_type()

Gets the type of the elements contained in the container.

Returns:

The type of the elements. None means that it is a multi-type container and you cannot determine the exact types with this interface.

Return type:

Any

has_by_name(name)

Checks if the container has an element with the specified name.

Parameters:

name (str) – The name of the element.

Returns:

True if the container has an element with the specified name, otherwise False.

Return type:

bool

has_elements()

Determines whether the container has elements.

Return type:

bool

qi(atype, raise_err=False)

Generic method that get an interface instance from an object.

Parameters:
  • atype (T) – Interface type to query obj for. Any Uno class that starts with ‘X’ such as XInterface

  • raise_err (bool, optional) – If True then raises MissingInterfaceError if result is None. Default False

Raises:

MissingInterfaceError – If ‘raise_err’ is ‘True’ and result is None

Returns:

instance of interface if supported; Otherwise, None

Return type:

T | None

Note

When raise_err=True return value will never be None.

property component: com.sun.star.text.TextTables

TextTables Component

Return type:

TextTables

property lo_inst: LoInst

Lo Instance

Return type:

LoInst

property office_doc: OfficeDocumentT

Office Document.

Return type:

OfficeDocumentT

property owner: T

Owner of this component.

Return type:

TypeVar(T, bound= ComponentT)

property write_doc: WriteDoc

Write Document.

Return type:

WriteDoc