RTFStringArray module

class RTFStringArray.RTFStringArray

Bases: XlsObject, IRichTextString, IOptimizedUpdate

Represents an array of rich text strings in Excel.

This class implements the IRichTextString and IOptimizedUpdate interfaces and provides functionality for managing arrays of rich text strings in Excel worksheets. It allows for formatting and manipulating the text content of multiple text strings.

Append(text: str, font: IFont)

Appends text with the specified font to the end of the text string array.

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

  • font (IFont) – The font to apply to the appended text.

BeginUpdate()

Begins a batch update operation on the string array.

This method marks the start of a series of changes to the string array. Multiple changes can be made more efficiently by calling BeginUpdate before making the changes and EndUpdate after all changes are complete.

Clear()

Clears both the text content and formatting of the string array.

This method removes all text and formatting information, resulting in empty text strings.

ClearFormatting()

Clears all formatting from the text strings.

This method removes all formatting information while preserving the text content, resulting in plain text with default formatting.

EndUpdate()

Ends a batch update operation on the string array.

This method should be called after BeginUpdate and all desired changes have been made. It applies all pending changes to the string array.

GetFont(iPosition: int) IFont

Gets the font used at the specified character position in the text.

Parameters:

iPosition (int) – The zero-based character position in the text.

Returns:

The font object used at the specified position.

Return type:

IFont

property IsFormatted: bool

Gets whether the text strings contain any formatting.

Returns:

True if the text contains formatting (different fonts, colors, etc.);

otherwise, False.

Return type:

bool

property RtfText: str

Gets the text content in Rich Text Format (RTF).

This property returns the text with all formatting information encoded in RTF format, which can be used for interoperability with other applications that support RTF.

Returns:

The text content in RTF format.

Return type:

str

SetFont(iStartPos: int, iEndPos: int, font: IFont)

Sets the font for a range of characters in the text.

Parameters:
  • iStartPos (int) – The zero-based starting character position.

  • iEndPos (int) – The zero-based ending character position (inclusive).

  • font (IFont) – The font to apply to the specified range of characters.

property Text: str

Gets or sets the plain text content of the string array.

When setting this property, any existing formatting is preserved and applied to the new text content where applicable.

Returns:

The plain text content without formatting information.

Return type:

str