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.TextCursorservice.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_datais a dictionary containingnameandcursor.
- 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.TextEmbeddedObjectservice are applied.
- Raises:
CreateInstanceMsfError – If unable to create text.TextEmbeddedObject
CancelEventError – If event
WriteNamedEvent.FORMULA_ADDINGis cancelledException – If unable to add formula
- Returns:
Embedded Object.
- Return type:
- Events:
Hint
Styles that can be applied are found in the following packages.
Note
Event args
event_datais a dictionary containingformulaandcursor.
- add_hyperlink(label, url_str)[source]
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_datais a dictionary containinglabel,url_strandcursor.
- add_image_link(fnm: Any) ooodev.write.write_text_content.WriteTextContent[ooodev.write.partial.text_cursor_partial._T][source]
- 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 mmor Class UnitT.height (int, UnitT) – Height in
1/100th mmor Class UnitT.styles (Sequence[StyleT]) – One or more styles to apply to frame. Only styles that support
com.sun.star.text.TextGraphicObjectservice are applied.
- Raises:
CreateInstanceMsfError – If Unable to create text.TextGraphicObject.
MissingInterfaceError – If unable to obtain XPropertySet interface.
Exception – If unable to add image.
CancelEventError – If
IMAGE_LINK_ADDINGevent is canceled.
- 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_datais a dictionary containingdoc,cursor,fnm,widthandheight.
- 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:
fnm (PathOrStr) – Image path.
width (int, UnitT) – Width in
1/100th mmor Class UnitT.height (int, UnitT) – Height in
1/100th mmor Class UnitT.
- Raises:
CreateInstanceMsfError – If unable to create drawing.GraphicObjectShape.
ValueError – If unable to get image.
MissingInterfaceError – If require interface cannot be obtained.
Exception – If unable to add image shape.
CancelEventError – if
IMAGE_SHAPE_ADDINGevent is canceled.
- Returns:
Image Shape on success; Otherwise,
None.- Return type:
- Events:
Note
Event args
event_datais a dictionary containingdoc,cursor,fnm,widthandheight.
- add_line_divider(line_width)[source]
Adds a line divider
- Parameters:
line_width (int) – Line width
- Raises:
CreateInstanceMsfError – If unable to create drawing.LineShape instance
MissingInterfaceError – If unable to obtain XShape interface
Exception – If unable to add Line divider
- 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 toNone.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 toNone.tbl_fg_color (
Color, optional) – Table background color. Set to None to ignore background color. Defaults toNone.first_row_header (bool, optional) – If
TrueFirst row is treated as header data. DefaultTrue.styles (Sequence[StyleT], optional) – One or more styles to apply to frame. Only styles that support
com.sun.star.text.TextTableservice are applied.
- Raises:
ValueError – If table_data is empty
CreateInstanceMsfError – If unable to create instance of text.TextTable
CancelEventError – If
WriteNamedEvent.TABLE_ADDINGevent cancelledException – If unable to add table
- Returns:
Table that is added to document.
- Return type:
- Events:
Note
Event args
event_datais 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 mmor Class UnitT. Default300.width (int, UnitT, optional) – Width in
1/100th mmor Class UnitT.height (int, UnitT, optional) – Height in
1/100th mmor Class UnitT.page_num (int, optional) – Page Number to add text frame. If
0Then Frame is anchored to paragraph. Default1.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.TextFrameservice are applied.
- Raises:
CreateInstanceMsfError – If unable to create text.TextFrame
CancelEventError – If
WriteNamedEvent.TEXT_FRAME_ADDINGevent is cancelledException – If unable to add text frame
- Returns:
Text frame that is added to document.
- Return type:
- Events:
Hint
Styles that can be applied are found in ooodev.format.writer.direct.frame subpackages.
Note
Event args
event_datais a dictionary containing all method args.See also
- 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.
See also
- 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
textis 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
textis 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.
- 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
- 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
posto apply style.styles (Sequence[StyleT]) – One or more styles to apply to text.
prop_name (str) – Property Name such as
CharHeightprop_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
CharHeightprop_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()