Rich Text API 参考
概述
Richtext API 提供创建和操作 Excel 单元格中富文本内容的函数,允许在单个单元格内使用多种样式的格式化文本。
富文本信息
-
int rt_segments_num(RichtextHandle rt)
获取富文本中的文本段数量。
- 参数:
rt -- Richtext 句柄
- 返回:
文本段数量。
-
const char *rt_plain_text(RichtextHandle rt)
获取富文本的纯文本内容。
- 参数:
rt -- Richtext 句柄
- 返回:
纯文本字符串。
文本段操作
-
const char *rt_text(RichtextHandle rt, int index, StyleHandle *style)
获取特定文本段的文本和样式。
- 参数:
rt -- Richtext 句柄
index -- 文本段索引(0-based)。
style -- 存储文本段样式句柄的指针。
- 返回:
文本段的文本内容。
-
void rt_append(RichtextHandle rt, const char *s, StyleHandle style)
向富文本追加新的文本段。
- 参数:
rt -- Richtext 句柄
s -- 要追加的文本内容。
style -- 新文本段的样式。
-
void rt_insert(RichtextHandle rt, int index, const char *s, StyleHandle style)
在指定位置插入新的文本段。
- 参数:
rt -- Richtext 句柄
index -- 插入文本段的位置。
s -- 要插入的文本内容。
style -- 新文本段的样式。
-
void rt_remove(RichtextHandle rt, int index)
从富文本中移除文本段。
- 参数:
rt -- Richtext 句柄
index -- 要移除的文本段索引。
-
void rt_modify(RichtextHandle rt, int index, const char *s, StyleHandle style)
修改现有的文本段。
- 参数:
rt -- Richtext 句柄
index -- 要修改的文本段索引。
s -- 新的文本内容。
style -- 文本段的新样式。
资源管理
-
void rt_release(RichtextHandle rt)
释放富文本资源。
- 参数:
rt -- 要释放的富文本句柄。
使用示例
富文本的典型使用模式:
// Create rich text from workbook
RichtextHandle rt = wb_make_richtext(workbook);
// Append segments with different styles
rt_append(rt, "This is ", normal_style);
rt_append(rt, "bold", bold_style);
rt_append(rt, " and ", normal_style);
rt_append(rt, "italic", italic_style);
rt_append(rt, " text.", normal_style);
// Apply to cell
ws_set_richtext(worksheet, 1, 1, rt);
// Release when done
rt_release(rt);