Class Write

class ooodev.office.write.Write[source]

Bases: Selection

class CompareEnum(value)

Bases: IntEnum

Compare Enumeration

__init__()
classmethod add_bookmark(cursor, name)[source]

Adds bookmark.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:
  • cursor (XTextCursor) – Text Cursor.

  • 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.

classmethod add_formula(cursor: com.sun.star.text.XTextCursor, formula: str) com.sun.star.text.XTextContent[source]
classmethod add_formula(cursor: com.sun.star.text.XTextCursor, formula: str, styles: Sequence[ooodev.proto.style_obj.StyleT]) com.sun.star.text.XTextContent
classmethod add_formula(cursor, formula, styles=None)

Adds a formula.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:
  • cursor (XTextCursor) – Cursor.

  • 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:

XTextContent

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.

Changed in version 0.9.0: Now returns the embedded Object instead of bool value. Added style parameter that allows for all styles that support com.sun.star.text.TextEmbeddedObject service.

Add a hyperlink.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:
  • cursor (XTextCursor) – Text Cursor.

  • 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.

classmethod add_image_link(doc: com.sun.star.text.XTextDocument, cursor: com.sun.star.text.XTextCursor, fnm: Any, *, width: int | UnitT, height: int | UnitT) com.sun.star.text.XTextContent
classmethod add_image_link(doc: com.sun.star.text.XTextDocument, cursor: com.sun.star.text.XTextCursor, fnm: Any, *, styles: Sequence[ooodev.proto.style_obj.StyleT]) com.sun.star.text.XTextContent
classmethod add_image_link(doc: com.sun.star.text.XTextDocument, cursor: com.sun.star.text.XTextCursor, fnm: Any, *, width: int | UnitT, height: int | UnitT, styles: Sequence[ooodev.proto.style_obj.StyleT]) com.sun.star.text.XTextContent
classmethod add_image_link(doc, cursor, fnm, *, width=0, height=0, styles=None)

Add Image Link.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:
  • doc (XTextDocument) – Text Document.

  • cursor (XTextCursor) – Text Cursor.

  • 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.

Changed in version 0.16.0: Raises CancelEventError if event is canceled.

Changed in version 0..0: Return image shape instead of boolean.

classmethod add_image_shape(cursor: com.sun.star.text.XTextCursor, fnm: Any) com.sun.star.drawing.XShape[source]
classmethod add_image_shape(cursor: com.sun.star.text.XTextCursor, fnm: Any, width: int | UnitT, height: int | UnitT) com.sun.star.drawing.XShape
classmethod add_image_shape(cursor, fnm, width=0, height=0)

Add Image Shape.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:
  • cursor (XTextCursor) – Text Cursor.

  • 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.

Raises:
Returns:

Image Shape on success; Otherwise, None.

Return type:

XShape

Events:

Note

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

Changed in version 0.16.0: Raises CancelEventError if event is canceled.

Changed in version 0.9.0: Return image shape instead of boolean.

classmethod add_line_divider(cursor, line_width)[source]

Adds a line divider.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:
  • cursor (XTextCursor) – Text Cursor.

  • line_width (int) – Line width.

Raises:
Return type:

None

classmethod add_table(cursor, table_data, header_bg_color=139, header_fg_color=16777215, tbl_bg_color=11393254, tbl_fg_color=0, 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.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:
  • cursor (XTextCursor) – Text Cursor.

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

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

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

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

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

  • 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:

XTextTable

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.

Changed in version 0.9.0: Now returns added table instead of bool value. Added options first_row_header and styles.

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

Adds a text frame.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:
  • cursor (XTextCursor) – Text Cursor.

  • 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:

XTextFrame

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.

Changed in version 0.9.0: Now returns the added text frame instead of bool value. Added UnitMM values. border_color and background_color now default to None. Added style parameter that allows for all styles that support com.sun.star.text.TextFrame service.

classmethod append(cursor: com.sun.star.text.XTextCursor, text: str)[source]
classmethod append(cursor: com.sun.star.text.XTextCursor, text: str)
classmethod append(cursor: com.sun.star.text.XTextCursor, ctl_char: ooo.dyn.text.control_character.ControlCharacterEnum)
classmethod append(cursor: com.sun.star.text.XTextCursor, text_content: com.sun.star.text.XTextContent)
classmethod append(*args, **kwargs)

Append content to cursor.

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • cursor (XTextCursor) – Text Cursor.

  • 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.

Changed in version 0.9.0: Added append(cursor: XTextCursor, text: str, styles: Sequence[StyleT]) overload.

Added Events.

classmethod append_date_time(cursor)[source]

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

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:

cursor (XTextCursor) – Text Cursor.

Raises:

MissingInterfaceError – If required interface cannot be obtained.

Return type:

None

classmethod append_line(cursor: com.sun.star.text.XTextCursor) None[source]
classmethod append_line(cursor: com.sun.star.text.XTextCursor, text: str) None
classmethod append_line(cursor: com.sun.star.text.XTextCursor, text: str, styles: Sequence[ooodev.proto.style_obj.StyleT]) None
classmethod append_line(cursor, text='', styles=None)

Appends a new Line.

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • cursor (XTextCursor) – Text Cursor.

  • 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.

Changed in version 0.9.0: Added overload append_line(cursor: XTextCursor, text: str, styles: Sequence[StyleT]).

Added events.

classmethod append_para(cursor: com.sun.star.text.XTextCursor) None[source]
classmethod append_para(cursor: com.sun.star.text.XTextCursor, text: str) None
classmethod append_para(cursor: com.sun.star.text.XTextCursor, text: str, styles: Sequence[ooodev.proto.style_obj.StyleT]) None
classmethod append_para(cursor, text='', styles=None)

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

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • cursor (XTextCursor) – Text Cursor.

  • 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.

Changed in version 0.9.0: Added overload append_para(cursor: XTextCursor, text: str, styles: Sequence[StyleT]).

Added Events.

classmethod close_doc() bool[source]
classmethod close_doc(text_doc: com.sun.star.text.XTextDocument) bool
classmethod close_doc(text_doc=None)

Closes text document.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

text_doc (XTextDocument) – Text Document.

Raises:

MissingInterfaceError – If unable to obtain XCloseable from text_doc.

Returns:

False if DOC_CLOSING event is canceled, Other.

Return type:

bool

Events:

Note

Event args event_data is a dictionary containing text_doc.

Attention

Lo.close method is called along with any of its events.

Changed in version 0.9.0: Added overload close_doc()

classmethod column_break(cursor)[source]

Inserts a column break.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

cursor (XTextCursor) – Text Cursor

Return type:

None

classmethod compare_cursor_ends(c1, c2)

Compares two cursors ranges end positions.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:
  • c1 (XTextRange) – first cursor range

  • c2 (XTextRange) – second cursor range

Raises:

Exception – if comparison fails

Returns:

Compare result. CompareEnum.BEFORE if c1 end position is before c2 end position. CompareEnum.EQUAL if c1 end position is equal to c2 end position. CompareEnum.AFTER if c1 end position is after c2 end position.

Return type:

CompareEnum

static create_doc() com.sun.star.text.XTextDocument[source]
static create_doc(loader: com.sun.star.frame.XComponentLoader) com.sun.star.text.XTextDocument
static create_doc(loader: com.sun.star.frame.XComponentLoader, props: Iterable[ooo.lo.beans.property_value.PropertyValue]) com.sun.star.text.XTextDocument
static create_doc(*, props: Iterable[ooo.lo.beans.property_value.PropertyValue]) com.sun.star.text.XTextDocument
static create_doc(loader=None, props=None)

Creates a new Writer Text Document.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:
  • loader (XComponentLoader) – Component Loader.

  • props (Iterable[PropertyValue]) – Property values.

Returns:

Text Document.

Return type:

XTextDocument

Events:

Note

Event args event_data is a dictionary containing loader.

Attention

Lo.create_doc method is called along with any of its events.

Changed in version 0.48.0: added new arg props

static create_doc_from_template(template_path: Any) com.sun.star.text.XTextDocument[source]
static create_doc_from_template(template_path: Any, loader: com.sun.star.frame.XComponentLoader) com.sun.star.text.XTextDocument
static create_doc_from_template(template_path, loader=None)

Create a new Writer Text Document from a template.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:
  • template_path (PathOrStr) – Path to Template.

  • loader (XComponentLoader) – Component Loader.

Raises:

MissingInterfaceError – If Unable to obtain XTextDocument interface.

Returns:

Text Document.

Return type:

XTextDocument

Events:

Note

Event args event_data is a dictionary containing template_path and loader.

Attention

Lo.create_doc_from_template method is called along with any of its events.

static create_style_char(text_doc, style_name, styles=None)[source]

Creates a character style and adds it to document character styles.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:
  • text_doc (XTextDocument) – Text Document

  • style_name (str) – The name of the character style.

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

Returns:

Newly created style

Return type:

XStyle

New in version 0.9.2.

static create_style_para(text_doc, style_name, styles=None)[source]

Creates a paragraph style and adds it to document paragraph styles.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:
  • text_doc (XTextDocument) – Text Document.

  • style_name (str) – The name of the paragraph style.

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

Returns:

Newly created style.

Return type:

XStyle

New in version 0.9.2.

classmethod dicts_info()[source]

Prints dictionary info to console.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Return type:

None

classmethod dispatch_cmd_left(vcursor, pos, cmd, props=None, frame=None, toggle=False)[source]

Dispatches a command and applies it to selection based upon position.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:
  • vcursor (XTextViewCursor) – Text View Cursor.

  • pos (int) – Positions left to apply dispatch command.

  • cmd (str) – Dispatch command such as ‘DefaultNumbering’.

  • props (Iterable[PropertyValue], optional) – properties for dispatch.

  • frame (XFrame, optional) – Frame to dispatch to.

  • toggle (bool, optional) – If True then dispatch will be preformed on selection. and again when deselected. Defaults to False.

Return type:

None

Note

Some commands such as DefaultNumbering require toggling. In such cases set arg toggle = True.

Following Example Sets last three lines to to a numbered list.

cursor = Write.get_cursor(doc)
Write.append_para(cursor, "The following points are important:")
pos = Write.get_position(cursor)
Write.append_para(cursor, "Have a good breakfast")
Write.append_para(cursor, "Have a good lunch")
Write.append_para(cursor, "Have a good dinner")

tvc = Write.get_view_cursor(doc)
tvc.gotoEnd(False)
Write.dispatch_cmd_left(vcursor=tvc, pos=pos, cmd="DefaultNumbering", toggle=True)

Attention

Lo.dispatch_cmd method is called along with any of its events.

classmethod end_line(cursor)[source]

Inserts a line break.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

cursor (XTextCursor) – Text Cursor

Return type:

None

classmethod end_paragraph(cursor)[source]

Inserts a paragraph break.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

cursor (XTextCursor) – Text Cursor

Return type:

None

static find_bookmark(text_doc, bm_name)[source]

Finds a bookmark.

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • text_doc (XTextDocument) – Text Document.

  • bm_name (str) – Bookmark name.

Raises:

MissingInterfaceError – if text_doc does not implement XBookmarksSupplier interface.

Returns:

Bookmark if found; Otherwise, None.

Return type:

XTextContent | None

static get_all_text(cursor)[source]

Gets the text part of the document.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

cursor (XTextCursor) – Text Cursor.

Returns:

text.

Return type:

str

static get_coord_str(tv_cursor)[source]

Gets coordinates for cursor in format such as "10, 10"

Method is Lo Instance Safe for use with multiple documents.

Parameters:

tv_cursor (XTextViewCursor) – Text View Cursor

Returns:

coordinates as string

Return type:

str

Warning

The X is relative to the document window and not the document page. This means when the document window size changes the X coordinate will change even if the cursor has not moved. This is also the case if the document zoom changes.

When the document page is zoomed all the way to fill the document window the X coordinate is 0 when at the left hand page margin (beginning of a line).

The Y coordinate is relative to the top of the document window and not the top of the document page. The Y coordinate seems not to be affected by Document Zoom or scroll position.

static get_current_page(tv_cursor)[source]

Gets the current page.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

tv_cursor (XTextViewCursor) – Text view Cursor

Returns:

Page number if present; Otherwise, -1

Return type:

int

static get_cursor()[source]
static get_cursor(cursor_obj: Any)
static get_cursor(rng: com.sun.star.text.XTextRange, txt: com.sun.star.text.XText)
static get_cursor(rng: com.sun.star.text.XTextRange, text_doc: com.sun.star.text.XTextDocument)
static get_cursor(*args, **kwargs)

Gets text cursor.

Parameters:
  • cursor_obj (DocOrCursor) – Text Document or Text View Cursor

  • rng (XTextRange) – Text Range Instance

  • text_doc (XTextDocument) – Text Document instance

Raises:

CursorError – If Unable to get cursor

Returns:

Cursor

Return type:

XTextCursor

Changed in version 0.9.0: Added overload get_cursor()

static get_dict_type(dt)[source]

Gets dictionary type.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

dt (DictionaryType) – Dictionary Type

Returns:

positive, negative, mixed, or ?? if unknown

Return type:

str

static get_doc_settings()[source]

Gets Text Document Settings.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Returns:

Settings

Return type:

XPropertySet

New in version 0.9.7.

static get_draw_page(text_doc)[source]

Gets draw page.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

text_doc (XTextDocument) – Text Document.

Raises:

MissingInterfaceError – If text_doc does not implement XDrawPageSupplier interface.

Returns:

Draw Page.

Return type:

XDrawPage

static get_draw_pages(text_doc)[source]

Gets draw pages.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

text_doc (XTextDocument) – Text Document.

Raises:

MissingInterfaceError – If text_doc does not implement XDrawPageSupplier interface.

Returns:

Draw Page.

Return type:

XDrawPages

static get_enumeration(obj)[source]

Gets Enumeration access from obj.

Method is Lo Instance Safe for use with multiple documents.

Used to enumerate objects in a container which contains objects.

Parameters:

obj (Any) – object that implements XEnumerationAccess or XTextDocument.

Raises:

MissingInterfaceError – if obj does not implement XEnumerationAccess interface.

Returns:

Enumerator.

Return type:

XEnumeration

Gets graphic links.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

doc (XComponent) – Document.

Raises:

MissingInterfaceError – if doc does not implement XTextGraphicObjectsSupplier interface.

Returns:

Graphic Links on success, Otherwise, None.

Return type:

XNameAccess | None

classmethod get_left_cursor(o_sel, o_text)

Creates a new TextCursor with position left that can travel right.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:
  • o_sel (XTextRange) – Text Range.

  • o_text (DocOrText) – Text document or text.

Returns:

a new instance of a TextCursor which is located at the specified TextRange to travel in the given text context.

Return type:

XTextCursor

static get_lingu_properties()[source]

Gets Lingu Properties.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Raises:

CreateInstanceMcfError – If unable to create com.sun.star.linguistic2.LinguProperties instance

Returns:

Properties

Return type:

XLinguProperties

static get_num_of_pages(text_doc)[source]

Gets document page count.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

text_doc (XTextDocument) – Text Document.

Raises:

MissingInterfaceError – If text_doc does not implement XModel interface.

Returns:

page count.

Return type:

int

static get_page_count(numbering_type=NumberingTypeEnum.ARABIC)[source]

Return Arabic style number showing current page count/

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:

numbering_type (NumberingTypeEnum, optional) – Numbering Type. Defaults to NumberingTypeEnum.ARABIC.

Returns:

Page Count as Text Field

Return type:

XTextField

classmethod get_page_cursor(view_cursor_obj)[source]

Get Page cursor.

Method is Lo Instance Safe for use with multiple documents.

Makes it possible to perform cursor movements between pages.

Parameters:
  • text_doc (XTextDocument | XTextViewCursor) – Text Document or View Cursor.

  • view_cursor_obj (XTextDocument | XTextViewCursor) –

Raises:

PageCursorError – If Unable to get cursor.

Returns:

Page Cursor.

Return type:

XPageCursor

static get_page_number(numbering_type=NumberingTypeEnum.ARABIC, sub_type=PageNumberType.CURRENT)[source]

Gets Arabic style number showing current page value.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:
  • numbering_type (NumberingTypeEnum, optional) – Numbering Type. Defaults to NumberingTypeEnum.ARABIC.

  • sub_type (PageNumberType, optional) – Page Number Type. Defaults to PageNumberType.CURRENT.

Returns:

Page Number as Text Field

Return type:

XTextField

static get_page_size(text_doc)[source]

Get page size in 1/100 mm units.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

text_doc (XTextDocument) – Text Document

Raises:
  • PropertiesError – If unable to access properties

  • Exception – If unable to get page size

Returns:

Page Size in 1/100 mm units.

Return type:

Size

static get_page_text_size(text_doc)[source]

Get page text size in 1/100 mm units.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

text_doc (XTextDocument) – Text Document

Raises:
  • PropertiesError – If unable to access properties

  • Exception – If unable to get page size

Returns:

Page text Size in 1/100 mm units.

Return type:

Size

New in version 0.9.0.

static get_page_text_width(text_doc)[source]

Get the width of the page’s text area in 1/100 mm units.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

text_doc (XTextDocument) – Text Document

Returns:

Page Width in 1/100 mm units on success; Otherwise 0

Return type:

int

classmethod get_paragraph_cursor(cursor_obj)

Gets document paragraph cursor.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

cursor_obj (DocOrCursor) – Text Document or Text Cursor.

Raises:

ParagraphCursorError – If Unable to get cursor.

Returns:

Paragraph cursor.

Return type:

XParagraphCursor

classmethod get_position(cursor)

Gets position of the cursor.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

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.

classmethod get_right_cursor(o_sel, o_text)

Creates a new TextCursor with position right that can travel left.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:
  • o_sel (XTextRange) – Text Range

  • o_text (DocOrText) – Text document or text.

Returns:

a new instance of a TextCursor which is located at the specified TextRange to travel in the given text context.

Return type:

XTextCursor

static get_selected_text_range(text_doc)

Gets the text range for current selection.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

text_doc (XTextDocument) – Text Document.

Raises:

MissingInterfaceError – If unable to obtain required interface.

Returns:

If no selection is made then None is returned; Otherwise, Text Range.

Return type:

XTextRange | None

Note

Writer must be visible for this method or None is returned.

classmethod get_selected_text_str(text_doc)

Gets the first selection text for Document.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

text_doc (XTextDocument) – Text Document.

Returns:

Selected text or empty string.

Return type:

str

Note

Writer must be visible for this method or empty string is returned.

classmethod get_sentence_cursor(cursor_obj)

Gets document sentence cursor.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

cursor_obj (DocOrCursor) – Text Document or Text Cursor.

Raises:

SentenceCursorError – If Unable to get cursor.

Returns:

Sentence Cursor.

Return type:

XSentenceCursor

Changed in version 0.16.0: Now raises SentenceCursorError instead of returning None.

static get_shapes(text_doc)[source]

Gets shapes.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

text_doc (XTextDocument) – Text Document.

Raises:

MissingInterfaceError – If text_doc does not implement XDrawPageSupplier interface.

Returns:

shapes

Return type:

XDrawPage

classmethod get_text_cursor_props(text_doc)

Gets properties for document cursor.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

text_doc (XTextDocument) – Text Document

Raises:

MissingInterfaceError – If unable to obtain XPropertySet interface from cursor.

Returns:

Properties

Return type:

XPropertySet

classmethod get_text_doc() com.sun.star.text.XTextDocument[source]
classmethod get_text_doc(doc: com.sun.star.lang.XComponent) com.sun.star.text.XTextDocument
classmethod get_text_doc(doc=None)

Gets a writer document

When using this method in a macro the Lo.get_document() value should be passed as doc arg.

Parameters:

doc (XComponent) – Component to get writer document from

Raises:
Returns:

Writer document

Return type:

XTextDocument

Events:

Changed in version 0.9.0: Added overload get_text_doc()

static get_text_frames(doc)[source]

Gets document Text Frames.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

doc (XComponent) – Document

Raises:

MissingInterfaceError – if doc does not implement XTextFramesSupplier interface

Returns:

Text Frames on success, Otherwise, None

Return type:

XNameAccess | None

New in version 0.9.0.

classmethod get_text_graphics(text_doc)[source]

Gets text graphics.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

text_doc (XTextDocument) – Text Document.

Raises:

Exception – If unable to get text graphics.

Returns:

Text Graphics.

Return type:

List[XGraphic]

Note

If there is error getting a graphic link then it is ignored and not added to the return value.

classmethod get_text_view_cursor_prop_set(text_doc)

Gets properties for document view cursor.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

text_doc (XTextDocument) – Text Document.

Raises:

MissingInterfaceError – If unable to obtain XPropertySet interface from cursor.

Returns:

Properties.

Return type:

XPropertySet

static get_view_cursor(text_doc)

Gets document view cursor.

Describes a cursor in a text document’s view.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

text_doc (XTextDocument) – Text Document

Raises:

ViewCursorError – If Unable to get cursor

Returns:

Text View Cursor

Return type:

XTextViewCursor

static get_word_count_ooo(text, word_type=None, locale_lang=None)

Get the number of word in ooo way.

This method takes into account the current Locale.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:
  • text (str) – string to count the word of.

  • word_type (WordTypeEnum, optional) – type of words to count. Default WordTypeEnum.WORD_COUNT Import line from ooodev.utils.selection import WordTypeEnum.

  • locale_lang (str, optional) – Language such as ‘en-US’ used to process word boundaries. Defaults to LO’s current language.

Raises:

CreateInstanceMsfError – If unable to create i18n.BreakIterator service.

Returns:

The number of words.

Return type:

int

classmethod get_word_cursor(cursor_obj)

Gets document word cursor.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

cursor_obj (DocOrCursor) – Text Document or Text Cursor.

Raises:

WordCursorError – If Unable to get cursor.

Returns:

Word Cursor.

Return type:

XWordCursor

static guess_locale(test_str)[source]

Guesses Primary Language and returns results.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:

test_str (str) – text used to make guess.

Returns:

Local if guess succeeds; Otherwise, None.

Return type:

Locale | None

classmethod insert_para(cursor, para, para_style)[source]

Inserts a paragraph with a style applied.

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • cursor (XTextCursor) – Text Cursor

  • para (str) – Paragraph text

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

Return type:

None

static is_anchored_graphic(graphic)[source]

Gets if a graphic object is an anchored graphic.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

graphic (Any) – object that implements XServiceInfo.

Returns:

True if is anchored graphic; Otherwise, False.

Return type:

bool

static is_anything_selected(text_doc)

Determine if anything is selected.

If Write document is not visible this method returns false.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

text_doc (XTextDocument) – Text Document

Returns:

True if anything in the document is selected: Otherwise, False

Return type:

bool

Note

Writer must be visible for this method or False is always returned.

static is_text(doc)[source]

Gets if doc is an actual Writer document.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

doc (XComponent) – Document Component

Returns:

True if doc is Writer Document; Otherwise, False

Return type:

bool

static load_proofreader()[source]

Gets Proof Reader.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Raises:

CreateInstanceMcfError – If unable to create linguistic2.Proofreader instance.

Returns:

Proof Reader.

Return type:

XProofreader

static load_spell_checker()[source]

Gets spell checker.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Raises:

CreateInstanceMcfError – If unable to create com.sun.star.linguistic2.LinguServiceManager instance

Returns:

spell checker

Return type:

XSpellChecker

static load_thesaurus()[source]

Gets Thesaurus.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Raises:

CreateInstanceMcfError – If unable to create com.sun.star.linguistic2.LinguServiceManager instance

Returns:

Thesaurus.

Return type:

XThesaurus

classmethod open_doc() com.sun.star.text.XTextDocument[source]
classmethod open_doc(fnm: Any) com.sun.star.text.XTextDocument
classmethod open_doc(*, loader: com.sun.star.frame.XComponentLoader) com.sun.star.text.XTextDocument
classmethod open_doc(fnm: Any, *, loader: com.sun.star.frame.XComponentLoader) com.sun.star.text.XTextDocument
classmethod open_doc(fnm: Any, loader: com.sun.star.frame.XComponentLoader) com.sun.star.text.XTextDocument
classmethod open_doc(fnm: Any, loader: com.sun.star.frame.XComponentLoader, props: Iterable[ooo.lo.beans.property_value.PropertyValue]) com.sun.star.text.XTextDocument
classmethod open_doc(fnm: Any, *, props: Iterable[ooo.lo.beans.property_value.PropertyValue]) com.sun.star.text.XTextDocument
classmethod open_doc(*, props: Iterable[ooo.lo.beans.property_value.PropertyValue]) com.sun.star.text.XTextDocument
classmethod open_doc(fnm=None, loader=None, props=None)

Opens or creates a Text (Writer) document.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:
  • fnm (PathOrStr) – Writer file to open. If omitted then a new Writer document is returned.

  • loader (XComponentLoader) – Component loader

  • props (Optional[Iterable[PropertyValue]]) –

Raises:
  • Exception – If Document is Null

  • Exception – If Not a Text Document

  • MissingInterfaceError – If unable to obtain XTextDocument interface

  • CancelEventError – if DOC_OPENING event is canceled.

Returns:

Text Document

Return type:

XTextDocument

Events:

Note

Event args event_data is a dictionary containing fnm and loader.

If fnm is omitted then DOC_OPENED event will not be raised.

Attention

Lo.open_doc method is called along with any of its events.

Changed in version 0.48.0: added new arg props

classmethod open_flat_doc_using_text_template(fnm: Any, template_path: Any) com.sun.star.text.XTextDocument[source]
classmethod open_flat_doc_using_text_template(fnm: Any, template_path: Any, loader: com.sun.star.frame.XComponentLoader) com.sun.star.text.XTextDocument
classmethod open_flat_doc_using_text_template(fnm, template_path, loader=None)

Open a new text document applying the template as formatting to the flat XML file.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:
  • fnm (PathOrStr) – path to file.

  • template_path (PathOrStr) – Path to template file (ott).

  • loader (XComponentLoader) – Component Loader.

Raises:
  • UnOpenableError – If fnm is not able to be opened.

  • ValueError – If template_path is not ott file.

  • MissingInterfaceError – If template_path document does not implement XTextDocument interface.

  • ValueError – If unable to obtain cursor object.

  • Exception – Any other errors

Returns:

Text Document.

Return type:

XTextDocument | None

Events:

Note

Event args event_data is a dictionary containing fnm, template_path and loader.

Attention

Lo.create_doc_from_template method is called along with any of its events.

static open_sent_check_options()[source]

Open Options - Language Settings - English sentence checking.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Return type:

None

Attention

Lo.dispatch_cmd method is called along with any of its events.

static open_spell_grammar_dialog()[source]

Activate dialog in Tools > Spelling and Grammar…

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Return type:

None

Attention

Lo.dispatch_cmd method is called along with any of its events.

static open_thesaurus_dialog()[source]

Opens LibreOffice Thesaurus Dialog.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Return type:

None

Attention

Lo.dispatch_cmd method is called along with any of its events.

classmethod page_break(cursor)[source]

Inserts a page break.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

cursor (XTextCursor) – Text Cursor

Return type:

None

static print_avail_service_info(lingo_mgr, service, loc)[source]

Prints available service info to console.

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • lingo_mgr (XLinguServiceManager2) – Service Manger.

  • service (str) – Service Name.

  • loc (Locale) – Locale.

Return type:

None

static print_con_dicts_info(cd_lst)[source]

Prints Conversion dictionary list to console.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

cd_lst (XConversionDictionaryList) – conversion dictionary list

Return type:

None

static print_config_service_info(lingo_mgr, service, loc)[source]

Print config service info to console.

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • lingo_mgr (XLinguServiceManager2) – Service Manager.

  • service (str) – Service Name.

  • loc (Locale) – Locale.

Return type:

None

classmethod print_dicts_info(dict_list)[source]

Prints dictionaries info to console.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

dict_list (XSearchableDictionaryList) – dictionary list

Return type:

None

static print_locale(loc)[source]

Prints a locale to the console.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

loc (Locale) – Locale to print.

Return type:

None

static print_locales(service, loc)[source]

Print locales to console.

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • service (str) – Service.

  • loc (Iterable[Locale]) – Locale’s.

Return type:

None

static print_meaning(word: str, thesaurus: com.sun.star.linguistic2.XThesaurus) int[source]
static print_meaning(word: str, thesaurus: com.sun.star.linguistic2.XThesaurus, loc: com.sun.star.lang.Locale) int
static print_meaning(word, thesaurus, loc=None)

Prints word meanings found in thesaurus to console.

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • word (str) – Word to print meanings of.

  • thesaurus (XThesaurus) – thesaurus instance.

  • loc (Locale | None, optional) – Local used to query meanings. Default Locale("en", "US", "").

Returns:

Number of meanings found.

Return type:

int

classmethod print_page_size(text_doc)[source]

Prints Page size to console.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

text_doc (XTextDocument) – Text Document

Return type:

None

static print_proof_error(string, err)[source]

Prints proof errors to console.

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • string (str) – error string.

  • err (SingleProofreadingError) – Single proof reading error.

Return type:

None

classmethod print_services_info(lingo_mgr: com.sun.star.linguistic2.XLinguServiceManager2) None[source]
classmethod print_services_info(lingo_mgr: com.sun.star.linguistic2.XLinguServiceManager2, loc: com.sun.star.lang.Locale) None
classmethod print_services_info(lingo_mgr, loc=None)

Prints service info to console.

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • lingo_mgr (XLinguServiceManager2) – Service manager.

  • loc (Locale | None, Optional) – Locale. Default Locale("en", "US", "").

Return type:

None

classmethod proof_sentence(sent: str, proofreader: com.sun.star.linguistic2.XProofreader) int[source]
classmethod proof_sentence(sent: str, proofreader: com.sun.star.linguistic2.XProofreader, loc: com.sun.star.lang.Locale) int
classmethod proof_sentence(sent, proofreader, loc=None)

Proofs a sentence for en US.

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • sent (str) – sentence to proof.

  • proofreader (XProofreader) – Proof reader instance.

  • loc (Locale | None, optional) – Local used to do proof reading. Default Locale("en", "US", "").

Returns:

Number of word of sentence that did not pass proof reading.

Return type:

int

classmethod range_len(text_doc, o_sel)

Gets the distance between range start and range end.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:
  • o_sel (XTextCursor) – first cursor range

  • o_text (object) – XText object, usually document text object

  • text_doc (XTextDocument) –

Returns:

length of range

Return type:

int

Note

All characters are counted including paragraph breaks. In Writer it will display selected characters however, paragraph breaks are not counted.

static save_doc(text_doc, fnm)[source]

Saves text document.

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • text_doc (XTextDocument) – Text Document

  • fnm (PathOrStr) – Path to save as

Raises:

MissingInterfaceError – If text_doc does not implement XComponent interface

Returns:

True if doc is saved; Otherwise, False

Return type:

bool

Events:

Note

Event args event_data is a dictionary containing text_doc and fnm.

Attention

Lo.save_doc method is called along with any of its events.

classmethod select_next_word(text_doc)

Select the word right from the current cursor position.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

text_doc (XTextDocument) – Text Document

Returns:

True if go to next word succeeds; Otherwise, False.

Return type:

bool

Events:

Note

The method returning True does not necessarily mean that the cursor is located at the next word, or any word at all! This may happen for example if it travels over empty paragraphs.

Note

Event args event_data is a dictionary containing text_doc.

classmethod set_a4_page_format(text_doc)[source]

Set Page Format to A4

Method is Lo Instance Safe for use with multiple documents.

Parameters:

text_doc (XTextDocument) – Text Document

Returns:

True if page format is set; Otherwise, False

Return type:

bool

Attention

set_page_format() method is called along with any of its events.

static set_configured_services(lingo_mgr: com.sun.star.linguistic2.XLinguServiceManager2, service: str, impl_name: str) bool[source]
static set_configured_services(lingo_mgr: com.sun.star.linguistic2.XLinguServiceManager2, service: str, impl_name: str, loc: com.sun.star.lang.Locale) bool
static set_configured_services(lingo_mgr, service, impl_name, loc=None)

Set configured Services.

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • lingo_mgr (XLinguServiceManager2) – Service Manager

  • service (str) – Service Name

  • impl_name (str) – Service implementation name

  • loc (Locale | None, optional) – Local used to spell words. Default Locale("en", "US", "")

Returns:

True if CONFIGURED_SERVICES_SETTING event is not canceled; Otherwise, False.

Return type:

bool

Events:

Note

Event args event_data is a dictionary containing all method parameters.

Modify the footer via the page style for the document. Put the text on the right hand side in the header in a general font of 10pt.

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • text_doc (XTextDocument) – Text Document.

  • text (str) – Header Text.

  • styles (Sequence[StyleT]) – Styles to apply to the text.

Raises:
  • PropertiesError – If unable to access properties.

  • Exception – If unable to set header text.

Return type:

None

See also

set_header()

Note

The font applied is determined by Info.get_font_general_name().

New in version 0.9.2.

Return type:

None

Parameters:
  • text_doc (XTextDocument) –

  • text (str) –

  • styles (Sequence[StyleT] | None) –

classmethod set_header(text_doc, text, styles=None)[source]

Modify the header via the page style for the document. Put the text on the right hand side in the header in a general font of 10pt.

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • text_doc (XTextDocument) – Text Document.

  • text (str) – Header Text.

  • styles (Sequence[StyleT]) – Styles to apply to the text.

Raises:
  • PropertiesError – If unable to access properties.

  • Exception – If unable to set header text.

Return type:

None

See also

set_footer()

Note

The font applied is determined by Info.get_font_general_name().

Changed in version 0.9.2: Added styles parameter

Return type:

None

Parameters:
  • text_doc (XTextDocument) –

  • text (str) –

  • styles (Sequence[StyleT] | None) –

static set_page_format(text_doc, paper_format)[source]

Set Page Format.

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • text_doc (XTextDocument) – Text Document

  • paper_format (PaperFormat) – Paper Format.

Raises:

MissingInterfaceError – If text_doc does not implement XPrintable interface

Returns:

True if page format is set; Otherwise, False

Return type:

bool

Events:

Note

Event args event_data is a dictionary containing fnm.

classmethod set_page_numbers(text_doc)[source]

Modify the footer via the page style for the document. Put page number & count in the center of the footer in Times New Roman, 12pt.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:

text_doc (XTextDocument) – Text Document

Raises:
  • PropertiesError – If unable to get properties

  • Exception – If Unable to set page numbers

Returns:

Page Number Field

Return type:

XTextField

Changed in version 0.16.0: Returns XTextField.

classmethod spell_sentence(sent: str, speller: com.sun.star.linguistic2.XSpellChecker) int[source]
classmethod spell_sentence(sent: str, speller: com.sun.star.linguistic2.XSpellChecker, loc: com.sun.star.lang.Locale) int
classmethod spell_sentence(sent, speller, loc=None)

Spell Check sentence for en US

Parameters:
  • sent (str) – Sentence to spell check

  • speller (XSpellChecker) – spell checker instance

  • loc (Locale | None, optional) – Local used to spell words. Default Locale("en", "US", "")

Returns:

Number of words spelled incorrectly

Return type:

int

static spell_word(word: str, speller: com.sun.star.linguistic2.XSpellChecker) bool[source]
static spell_word(word: str, speller: com.sun.star.linguistic2.XSpellChecker, loc: com.sun.star.lang.Locale) bool
static spell_word(word, speller, loc=None)

Spell Check a word for en US.

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • word (str) – word to spell check.

  • speller (XSpellChecker) – spell checker instance.

  • loc (Locale | None, optional) – Local used to spell word. Default Locale("en", "US", "").

Returns:

True if no spelling errors are detected; Otherwise, False.

Return type:

bool

static split_paragraph_into_sentences(paragraph)[source]

Alternative method for breaking a paragraph into sentences and return a list.

XSentenceCursor occasionally does not divide a paragraph into the correct number of sentences; sometimes two sentences were treated as one.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

paragraph (str) – input string.

Returns:

List of string.

Return type:

List[str]

classmethod style(pos: int, length: int)[source]
classmethod style(pos: int, length: int)
classmethod style(pos: int, length: int)
classmethod style(pos: int, length: int)
classmethod style(*args, **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

  • cursor (XTextCursor) – Text Cursor

Return type:

None

See also

style_left()

Note

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

New in version 0.9.0.

classmethod style_left(cursor: com.sun.star.text.XTextCursor, pos: int)[source]
classmethod style_left(cursor: com.sun.star.text.XTextCursor, pos: int)
classmethod style_left(*args, **kwargs)

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

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:
  • cursor (XTextCursor) – Text Cursor

  • 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

Events:

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

Otherwise, the following events are triggered once.

Return type:

None

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.

Changed in version 0.9.0: Added style_left(cursor: XTextCursor, pos: int, styles: Sequence[StyleT]) overload.

Added Events.

classmethod style_left_bold(cursor, pos)[source]

Styles bold from current cursor position left by pos amount.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:
  • cursor (XTextCursor) – Text Cursor.

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

Return type:

None

classmethod style_left_code(cursor, pos)[source]

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

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:
  • cursor (XTextCursor) – Text Cursor.

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

Return type:

None

Note

The font applied is determined by Info.get_font_mono_name()

classmethod style_left_color(cursor, pos, color)[source]

Styles color from current cursor position left by pos amount.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:
  • cursor (XTextCursor) – Text Cursor.

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

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

Return type:

None

See also

CommonColor

classmethod style_left_italic(cursor, pos)[source]

Styles italic from current cursor position left by pos amount.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:
  • cursor (XTextCursor) – Text Cursor.

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

Return type:

None

classmethod style_prev_paragraph(cursor: com.sun.star.text.XTextCursor, styles: Sequence[ooodev.proto.style_obj.StyleT])[source]
classmethod style_prev_paragraph(cursor: com.sun.star.text.XTextCursor, prop_val: Any)
classmethod style_prev_paragraph(cursor: com.sun.star.text.XTextCursor, prop_val: Any)
classmethod style_prev_paragraph(*args, **kwargs)

Style previous paragraph.

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • cursor (XTextCursor) – Text Cursor.

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

  • prop_val (Any) – Property value.

  • prop_name (str) – Property Name. Defaults to ParaStyleName.

Events:

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

Otherwise the following events are triggered once.

Return type:

None

Example
cursor = Write.get_cursor(doc)
Write.style_prev_paragraph(cursor=cursor, prop_val=ParagraphAdjust.CENTER, prop_name="ParaAdjust")

Changed in version 0.9.0: Added overload style_prev_paragraph(cursor: XTextCursor, styles: Sequence[StyleT])

static toggle_auto_spell_check()[source]

Toggles spell check on and off.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Return type:

None

Attention

Lo.dispatch_cmd method is called along with any of its events.