Class TextCursorPartial

class ooodev.write.partial.text_cursor_partial.TextCursorPartial(owner, component, lo_inst=None)[source]

Represents a writer text cursor.

This class implements __len__() method, which returns the number of characters in the range.

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

Constructor

Parameters:
  • owner (_T) – Object that owns this component.

  • component (XTextCursor) – A UNO object that supports com.sun.star.text.TextCursor service.

  • lo_inst (LoInst | None) –

Return type:

None

add_bookmark(name)[source]

Adds a bookmark with the specified name to the cursor.

Parameters:

name (str) – Bookmark name

Returns:

True if bookmark is added; Otherwise, False

Return type:

bool

Events:

Note

Event args event_data is a dictionary containing name and cursor.

add_formula(formula: str) ooodev.write.write_text_content.WriteTextContent[ooodev.write.partial.text_cursor_partial._T][source]
add_formula(formula: str, styles: Sequence[ooodev.proto.style_obj.StyleT]) ooodev.write.write_text_content.WriteTextContent[ooodev.write.partial.text_cursor_partial._T]
add_formula(formula, styles=None)

Adds a formula

Parameters:
  • formula (str) – formula

  • styles (Sequence[StyleT]) – One or more styles to apply to frame. Only styles that support com.sun.star.text.TextEmbeddedObject service are applied.

Raises:
Returns:

Embedded Object.

Return type:

WriteTextContent

Events:

Hint

Styles that can be applied are found in the following packages.

Note

Event args event_data is a dictionary containing formula and cursor.

Add a hyperlink

Parameters:
  • label (str) – Hyperlink label

  • url_str (str) – Hyperlink url

Raises:
  • CreateInstanceMsfError – If unable to create TextField.URL instance

  • Exception – If unable to create hyperlink

Returns:

True if hyperlink is added; Otherwise, False

Return type:

bool

Events:

Note

Event args event_data is a dictionary containing label, url_str and cursor.

add_image_link(fnm: Any, *, width: int | UnitT, height: int | UnitT) ooodev.write.write_text_content.WriteTextContent[ooodev.write.partial.text_cursor_partial._T]
add_image_link(fnm: Any, *, styles: Sequence[ooodev.proto.style_obj.StyleT]) ooodev.write.write_text_content.WriteTextContent[ooodev.write.partial.text_cursor_partial._T]
add_image_link(fnm: Any, *, width: int | UnitT, height: int | UnitT, styles: Sequence[ooodev.proto.style_obj.StyleT]) ooodev.write.write_text_content.WriteTextContent[ooodev.write.partial.text_cursor_partial._T]
add_image_link(fnm, *, width=0, height=0, styles=None)

Add Image Link

Parameters:
  • fnm (PathOrStr) – Image path

  • width (int, UnitT) – Width in 1/100th mm or Class UnitT.

  • height (int, UnitT) – Height in 1/100th mm or Class UnitT.

  • styles (Sequence[StyleT]) – One or more styles to apply to frame. Only styles that support com.sun.star.text.TextGraphicObject service are applied.

Raises:
Returns:

Image Link on success; Otherwise, None.

Return type:

XTextContent

Events:

Hint

Styles that can be applied are found in the following packages.

Note

Event args event_data is a dictionary containing doc, cursor, fnm, width and height.

add_image_shape(fnm: Any) ooodev.adapter.drawing.graphic_object_shape_comp.GraphicObjectShapeComp[source]
add_image_shape(fnm: Any, width: int | UnitT, height: int | UnitT) ooodev.adapter.drawing.graphic_object_shape_comp.GraphicObjectShapeComp
add_image_shape(fnm, width=0, height=0)

Add Image Shape.

Parameters:
Raises:
Returns:

Image Shape on success; Otherwise, None.

Return type:

GraphicObjectShapeComp

Events:

Note

Event args event_data is a dictionary containing doc, cursor, fnm, width and height.

add_line_divider(line_width)[source]

Adds a line divider

Parameters:

line_width (int) – Line width

Raises:
Return type:

None

add_table(table_data, *, name='', header_bg_color=None, header_fg_color=None, tbl_bg_color=None, tbl_fg_color=None, first_row_header=True, styles=None)[source]

Adds a table.

Each row becomes a row of the table. The first row is treated as a header.

Parameters:
  • table_data (Table) – 2D Table with the the first row containing column names.

  • name (str, optional) – Table name.

  • header_bg_color (Color, optional) – Table header background color. Set to None to ignore header color. Defaults to None.

  • header_fg_color (Color, optional) – Table header foreground color. Set to None to ignore header color. Defaults to Defaults to ``None`.

  • tbl_bg_color (Color, optional) – Table background color. Set to None to ignore background color. Defaults to None.

  • tbl_fg_color (Color, optional) – Table background color. Set to None to ignore background color. Defaults to None.

  • first_row_header (bool, optional) – If True First row is treated as header data. Default True.

  • styles (Sequence[StyleT], optional) – One or more styles to apply to frame. Only styles that support com.sun.star.text.TextTable service are applied.

Raises:
  • ValueError – If table_data is empty

  • CreateInstanceMsfError – If unable to create instance of text.TextTable

  • CancelEventError – If WriteNamedEvent.TABLE_ADDING event cancelled

  • Exception – If unable to add table

Returns:

Table that is added to document.

Return type:

WriteTable

Events:

Note

Event args event_data is a dictionary containing all method args.

Hint

Styles that can be applied are found in ooodev.format.writer.direct.table subpackages.

add_text_frame(*, text='', ypos=300, width=5000, height=5000, page_num=1, border_color=None, background_color=None, styles=None)[source]

Adds a text frame.

Parameters:
  • text (str, optional) – Frame Text

  • ypos (int, UnitT. optional) – Frame Y pos in 1/100th mm or Class UnitT. Default 300.

  • width (int, UnitT, optional) – Width in 1/100th mm or Class UnitT.

  • height (int, UnitT, optional) – Height in 1/100th mm or Class UnitT.

  • page_num (int, optional) – Page Number to add text frame. If 0 Then Frame is anchored to paragraph. Default 1.

  • border_color (Color, optional) – .color.Color`, optional): Border Color.

  • background_color (Color, optional) – Background Color.

  • styles (Sequence[StyleT]) – One or more styles to apply to frame. Only styles that support com.sun.star.text.TextFrame service are applied.

Raises:
Returns:

Text frame that is added to document.

Return type:

WriteTextFrame

Events:

Hint

Styles that can be applied are found in ooodev.format.writer.direct.frame subpackages.

Note

Event args event_data is a dictionary containing all method args.

append(text: str)[source]
append(text: str, styles: Sequence[ooodev.proto.style_obj.StyleT])
append(ctl_char: ooo.dyn.text.control_character.ControlCharacterEnum)
append(text_content: com.sun.star.text.XTextContent)
append(*args, **kwargs)

Append content to cursor

Parameters:
  • text (str) – Text to append.

  • styles (Sequence[StyleT]) – One or more styles to apply to text.

  • ctl_char (int) – Control Char (like a paragraph break or a hard space).

  • text_content (XTextContent) – Text content, such as a text table, text frame or text field.

Return type:

None

Events:

If using styles then the following events are triggered for each style.

Hint

Styles that can be applied are found in the following packages.

append_date_time()[source]

Append two DateTime fields, one for the date, one for the time

Raises:

MissingInterfaceError – If required interface cannot be obtained.

Return type:

None

append_line() None[source]
append_line(text: str) None
append_line(text: str, styles: Sequence[ooodev.proto.style_obj.StyleT]) None
append_line(text='', styles=None)

Appends a new Line.

Parameters:
  • text (str, optional) – text to append before new line is inserted.

  • styles (Sequence[StyleT]) – One or more styles to apply to text. If text is omitted then this argument is ignored.

Return type:

None

Events:

If using styles then the following events are triggered for each style.

append_para() None[source]
append_para(text: str) None
append_para(text: str, styles: Sequence[ooodev.proto.style_obj.StyleT]) None
append_para(text='', styles=None)

Appends text (if present) and then a paragraph break.

Parameters:
  • text (str, optional) – Text to append

  • styles (Sequence[StyleT]) – One or more styles to apply to text. If text is empty then this argument is ignored.

Return type:

None

Events:

If using styles then the following events are triggered for each style.

Hint

Styles that can be applied are found in the following packages.

column_break()[source]

Inserts a column break

Return type:

None

end_line()[source]

Inserts a line break

Return type:

None

end_paragraph()[source]

Inserts a paragraph break

Return type:

None

get_all_text()[source]

Gets the text part of the document

Returns:

text

Return type:

str

get_pos()[source]

Gets position of the cursor

Parameters:

cursor (XTextCursor) – Text Cursor

Returns:

Current Cursor Position

Return type:

int

Note

This method is not the most reliable. It attempts to read all the text in a document and move the cursor to the end and then get the position.

It would be better to use cursors from relative positions in bigger documents.

insert_para(para, para_style)[source]

Inserts a paragraph with a style applied

Parameters:
  • para (str) – Paragraph text

  • para_style (str) – Style such as ‘Heading 1’

Return type:

None

page_break()[source]

Inserts a page break

Return type:

None

style(*, pos: int, length: int)[source]
style(*, pos: int, length: int)
style(**kwargs)

Styles. From position styles right by distance amount.

Parameters:
  • pos (int) – Position style start.

  • length (int) – The distance from pos to apply style.

  • styles (Sequence[StyleT]) – One or more styles to apply to text.

  • prop_name (str) – Property Name such as CharHeight

  • prop_val (object) – Property Value such as 10

Return type:

None

See also

style_left()

Note

Unlike style_left() this method does not restore any style properties after style is applied.

style_left(pos: int, styles: Sequence[ooodev.proto.style_obj.StyleT])[source]
style_left(pos: int, prop_name: str, prop_val: object)
style_left(*args, **kwargs)

Styles left. From current cursor position to left by pos amount.

Parameters:
  • pos (int) – Positions to style left

  • styles (Sequence[StyleT]) – One or more styles to apply to text.

  • prop_name (str) – Property Name such as CharHeight

  • prop_val (object) – Property Value such as 10

Return type:

None

Events:

If using styles then the following events are triggered for each style.

Otherwise, the following events are triggered once.

See also

style()

Note

This method restores the style properties to their original state after the style is applied. This is done so applied style properties are reset before next text is appended. This is not the case for style() method.

style_left_bold(pos)[source]

Styles bold from current cursor position left by pos amount.

Parameters:

pos (int) – Number of positions to go left

Return type:

None

style_left_code(pos)[source]

Styles using a Mono font from current cursor position left by pos amount. Font Char Height is set to 10

Parameters:

pos (int) – Number of positions to go left

Return type:

None

Note

The font applied is determined by Info.get_font_mono_name()

style_left_color(pos, color)[source]

Styles color from current cursor position left by pos amount.

Parameters:
  • pos (int) – Number of positions to go left

  • color (Color) – RGB color as int to apply

Return type:

None

See also

CommonColor

style_left_italic(pos)[source]

Styles italic from current cursor position left by pos amount.

Parameters:

pos (int) – Number of positions to go left

Return type:

None