Richtext Interface

The Richtext interface represents formatted text content with multiple segments , each potentially having different styling properties.

Classes

class oo::iRichtext

Interface for managing rich text content with multiple formatted segments.

Content Information

int segments_num() const

Get the number of text segments in the rich text.

Returns:

Number of text segments

const char *plain_text() const

Get the complete text content without formatting.

Returns:

Plain text content

Text Segment Access

const char *text(int index, iStyle **style = nullptr) const

Get text and style for a specific segment.

Parameters:
  • index – Segment index (0-based)

  • style – Pointer to store style object pointer (optional)

Returns:

Text content of the segment

Note

If the style parameter is provided and the segment has styling, the style object pointer will be stored.

Content Modification

void append(const char *s, iStyle *style = nullptr)

Append a new text segment to the rich text.

Parameters:
  • s – Text content to append

  • style – Style to apply to the new segment (optional)

void insert(int index, const char *s, iStyle *style = nullptr)

Insert a new text segment at the specified position.

Parameters:
  • index – Position to insert (0-based)

  • s – Text content to insert

  • style – Style to apply to the new segment (optional)

void remove(int index)

Remove a text segment.

Parameters:

index – Segment index to remove (0-based)

void modify(int index, const char *s, iStyle *style = nullptr)

Modify an existing text segment.

Parameters:
  • index – Segment index to modify (0-based)

  • s – New text content

  • style – New style to apply (optional, nullptr keeps existing style)

Resource Management

void release()

Release the rich text object and free associated resources.

Note

This should be called when the rich text object is no longer needed to prevent memory leaks.

Usage Example

#include "oosxl.hxx"

// Create rich text object
oo::iRichtext* richText = workbook->make_richtext();

// Create styles for different segments
oo::iStyle* boldStyle = workbook->make_normal_style();
boldStyle->set_bold(true);
boldStyle->set_font_size(14);

oo::iStyle* redStyle = workbook->make_normal_style();
redStyle->set_font_color(RGB(255, 0, 0));
redStyle->set_italic(true);

// Add formatted segments
richText->append("This is ", nullptr);  // Normal text
richText->append("bold", boldStyle);    // Bold text
richText->append(" and ", nullptr);     // Normal text
richText->append("red italic", redStyle); // Red italic text

// Apply to cell
worksheet->set_richtext(0, 0, richText);

// Get information about segments
int segmentCount = richText->segments_num();
for (int i = 0; i < segmentCount; ++i) {
    oo::iStyle* segmentStyle = nullptr;
    const char* text = richText->text(i, &segmentStyle);
    // Process segment...
}

// Get plain text
const char* plainText = richText->plain_text();
// plainText = "This is bold and red italic"

// Clean up
boldStyle->release();
redStyle->release();
richText->release();