RTFCommentArray module

class RTFCommentArray.RTFCommentArray

Bases: XlsObject, IRichTextString, IOptimizedUpdate

Represents an array of rich text comments in Excel.

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

Append(text: str, font: IFont)

Appends text with the specified font to the end of the comment text.

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 comment array.

This method marks the start of a series of changes to the comment 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 comments.

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

ClearFormatting()

Clears all formatting from the comment text.

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 comment array.

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

GetFont(iPosition: int) IFont

Gets the font used at the specified character position in the comment 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 comment text contains 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 comment 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 comment.

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