Class WriteText

class ooodev.write.WriteText(owner, component, lo_inst=None)[source]

Bases: LoInstPropsPartial, WriteDocPropPartial, TextComp, RelativeTextContentInsertPartial, QiPartial, StylePartial, Generic[T]

Represents writer text content.

Contains Enumeration Access.

__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

apply_styles(*styles, **kwargs)

Applies style to component.

Parameters:
  • obj. (styles expandable list of styles object such as Font to apply to) –

  • kwargs (Any, optional) – Expandable list of key value pairs.

  • styles (StyleT) –

Return type:

None

create_enumeration()

Creates an enumeration of the container’s elements.

Return type:

XEnumeration

create_text_cursor()[source]

Creates a new text cursor.

Returns:

The new text cursor.

Return type:

WriteTextCursor[WriteText]

create_text_cursor_by_range(text_position)[source]

The initial position is set to text_position.

Parameters:

text_position (WriteTextRange, XTextRange) – The initial position of the new text cursor.

Returns:

The new text cursor.

Return type:

WriteTextCursor[WriteText]

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

get_end()

Returns a text range which contains only the end of this text range.

Return type:

TextRangeComp

get_paragraphs()[source]

Returns the paragraphs of this text.

Return type:

WriteParagraphs[TypeVar(T, bound= ComponentT)]

get_start()

Returns a text range which contains only the start of this text range.

Return type:

TextRangeComp

get_string()

Returns the string of this text range.

Return type:

str

get_text()

Gets the text of the range.

Returns:

The text of the range.

Return type:

XText

has_elements()

Determines whether the container has elements.

Return type:

bool

insert_control_character(rng, control_character, absorb)

Inserts a control character (like a paragraph break or a hard space) into the text.

Parameters:
  • rng (XTextRange) – The position of the new control character.

  • control_character (ControlCharacterEnum) – The control character to be inserted.

  • absorb (bool) – If TRUE the text range will contain the new inserted control character, otherwise the range (and it’s text) will remain unchanged.

Raises:

IllegalArgumentExceptioncom.sun.star.lang.IllegalArgumentException

Return type:

None

insert_string(rng, text, absorb)

Inserts a string of characters into the text.

The string may contain the following white spaces:

If the parameter bAbsorb() was TRUE the text range will contain the new inserted string, otherwise the range (and it’s text) will remain unchanged.

Return type:

None

Parameters:
  • rng (XTextRange) –

  • text (str) –

  • absorb (bool) –

insert_text_content(content: com.sun.star.text.XTextContent, absorb: bool) None[source]
insert_text_content(content: com.sun.star.text.XTextContent, absorb: bool, rng: com.sun.star.text.XTextRange) None
insert_text_content(content, absorb, rng=None)

Inserts a content, such as a text table, text frame or text field.

Parameters:
  • rng (XTextRange) – The position at which the content is inserted.

  • content (XTextContent) – The content to be inserted.

  • absorb (bool) – Specifies whether the text spanned by xRange will be replaced. If True then the content of range will be replaced by content, otherwise content will be inserted at the end of xRange.

Return type:

None

insert_text_content_after(new_content, predecessor)

Inserts text the new text content after the predecessor argument.

This is helpful to insert paragraphs after text tables especially in headers, footers or text frames.

Parameters:
  • new_content (XTextContent) – The new text content.

  • predecessor (XTextContent) – The predecessor text content.

Raises:

com.sun.star.lang.IllegalArgumentExceptionIllegalArgumentException

Return type:

None

insert_text_content_before(new_content, successor)

inserts text the new text content before of the successor argument.

This is helpful to insert paragraphs before of text tables.

Parameters:
  • new_content (XTextContent) – The new text content.

  • successor (XTextContent) – The successor text content.

Raises:

com.sun.star.lang.IllegalArgumentExceptionIllegalArgumentException

Return type:

None

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.

remove_text_content(content)

Removes a text content.

Parameters:

content (XTextContent) – the content that is to be removed.

Return type:

None

set_string(string)

Sets the string of this text range.

The whole string of characters of this piece of text is replaced. All styles are removed when applying this method.

Return type:

None

Parameters:

string (str) –

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

Text Component

Return type:

Text

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