RichTextString module
- class RichTextString.RichTextString
Bases:
CommonWrapper,IRichTextString,IExcelApplicationRepresents a base class for rich text strings in Excel.
This class implements the IRichTextString and IExcelApplication interfaces and serves as a base class for other rich text implementations. It provides core functionality for creating and manipulating text with different formatting applied to different parts.
- Append(text: str, font: IFont)
Appends text with the specified font to the end of the rich text.
- Parameters:
text (str) – The text to append.
font (IFont) – The font to apply to the appended text.
- Clear()
Clears both the text content and formatting.
This method removes all text and formatting information, resulting in an empty rich text string.
- ClearFormatting()
Clears all formatting from the rich text.
This method removes all formatting information while preserving the text content, resulting in plain text with default formatting.
- property DefaultFont: XlsFont
Gets the default font for this rich text string.
The default font is used for any portion of the text that doesn’t have specific formatting applied.
- Returns:
The default font object for the rich text string.
- Return type:
- GetFont(index: int) IFont
Gets the font used at the specified character position in the text.
- Parameters:
index (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 rich text contains any formatting.
- Returns:
- True if the text contains formatting (different fonts, colors, etc.);
otherwise, False.
- Return type:
bool
- property Parent: SpireObject
Gets the parent object that contains this rich text string.
- Returns:
The parent object that contains this rich text string.
- Return type:
SpireObject
- 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(startIndex: int, endIndex: int, font: IFont)
Sets the font for a range of characters in the text.
- Parameters:
startIndex (int) – The zero-based starting character position.
endIndex (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 rich text string.
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
