RtfTextWriter module

class RtfTextWriter.RtfTextWriter

Bases: SpireObject

Provides functionality for writing Rich Text Format (RTF) content.

This class encapsulates methods for creating and manipulating RTF documents, including text formatting, font management, color management, and other RTF features. It is used internally by Excel components that need to generate RTF content.

AddColor(color: Color) int

Adds a color to the RTF document’s color table.

This method registers a color in the RTF document’s color table, making it available for use in text and background formatting.

Parameters:

color (Color) – The color to add to the color table.

Returns:

The index of the added color in the color table.

Return type:

int

AddFont(font: Font) int

Adds a font to the RTF document’s font table.

This method registers a font in the RTF document’s font table, making it available for use in text formatting.

Parameters:

font (Font) – The font to add to the font table.

Returns:

The index of the added font in the font table.

Return type:

int

property Encoding: Encoding

Gets the character encoding used for the RTF document.

Returns:

The character encoding used for the RTF document.

Return type:

Encoding

property Escape: bool

Gets or sets whether special characters should be escaped in the RTF output.

When set to True, special characters like braces, backslashes, etc. will be escaped with a backslash in the RTF output.

Returns:

True if special characters should be escaped; otherwise, False.

Return type:

bool

ToString() str

Converts the RTF content to a string representation.

Returns:

The RTF content as a string.

Return type:

str

Write
WriteBackColorAttribute(color: Color)
WriteColorTable()

Writes the color table to the RTF document.

This method outputs the RTF color table header and all registered colors to the RTF document. The color table must be written before any text that uses those colors.

WriteFont
WriteFontAttribute(font: Font)
WriteFontItalicBoldStriked(font: Font)
WriteFontTable()

Writes the font table to the RTF document.

This method outputs the RTF font table header and all registered fonts to the RTF document. The font table must be written before any text that uses those fonts.

WriteForeColorAttribute(color: Color)
WriteLine
WriteLineNoTabs(s: str)
WriteStrikeThrough(style: StrikeThroughStyle)
WriteSubSuperScript(font: XlsFont)
WriteTag
WriteText

Writes text with the specified font to the RTF document.

Parameters:
  • font (Font) – The font to apply to the text.

  • strText (str) – The text to write.

WriteUnderline(font: XlsFont)
WriteUnderlineAttribute