Richtext 接口
Richtext 接口代表具有多种格式的文本内容,包含多个文本段,每个文本段可以具有不同的样式属性。
类
-
class oo::iRichtext
管理具有多个格式段的富文本内容的接口。
文本信息
-
int segments_num() const
获取富文本中的文本段数量。
- 返回:
文本段数量
-
const char *plain_text() const
获取不带格式的完整的朴素文本内容。
- 返回:
纯文本内容
文本段访问
文本内容修改
-
void append(const char *s, iStyle *style = nullptr)
向富文本追加新的文本段。
- 参数:
s -- 要追加的文本内容
style -- 应用于新段的样式(可选)
-
void insert(int index, const char *s, iStyle *style = nullptr)
在指定位置插入新的文本段。
- 参数:
index -- 插入位置(0-based)
s -- 要插入的文本内容
style -- 应用于新段的样式(可选)
-
void remove(int index)
移除文本段。
- 参数:
index -- 要移除的段索引(0-based)
资源管理
-
void release()
释放富文本对象并清理相关资源。
备注
当不再需要 Richtext 对象时应调用此方法,以释放内存。
-
int segments_num() const
使用示例
#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();