TextRun — Aspose.Note FOSS for Python API Reference
类:TextRun
Properties: aspose.note Properties: from aspose.note import TextRun Properties: Node
TextRun 表示在 a 中共享统一格式的单个连续文本段 RichText 块。A RichText.TextRuns 列表包含一个或多个 TextRun 对象;每个都有其自己的 Style (TextStyle)。这是文档模型中格式化文本的最细粒度单元。.
Properties
| Properties | Properties | Properties | Properties |
|---|---|---|---|
Text | str | 读/写 | 此段的文本内容。默认值为 "". |
Style | TextStyle | 读/写 | 此段的格式属性。参见 TextStyle. |
Start | `int | None` | Properties |
End | `int | None` | Properties |
继承自 Node
| Properties | Properties | Properties |
|---|---|---|
ParentNode | `Node | None` |
Document | `Document | None` |
与 RichText 的关系
Properties RichText 节点拥有一个列表,包含 TextRun 对象,通过 RichText.TextRuns. 串联 run.Text 对所有运行产生完整的 RichText.Text:
RichText.Text == "".join(run.Text for run in RichText.TextRuns)每次运行携带独立的 Style,,因此单个段落可以包含混合的粗体、斜体、超链接或不同颜色的片段。.
使用示例
检查文档中的所有 run
from aspose.note import Document, RichText
doc = Document("MyNotes.one")
for rt in doc.GetChildNodes(RichText):
for run in rt.TextRuns:
s = run.Style
attrs = []
if s.Bold: attrs.append("bold")
if s.Italic: attrs.append("italic")
if s.Underline: attrs.append("underline")
if s.IsHyperlink: attrs.append(f"link={s.HyperlinkAddress!r}")
label = ", ".join(attrs) or "plain"
print(f"[{label}] {run.Text!r}")查找所有超链接 run
from aspose.note import Document, RichText
doc = Document("MyNotes.one")
for rt in doc.GetChildNodes(RichText):
for run in rt.TextRuns:
if run.Style.IsHyperlink and run.Style.HyperlinkAddress:
print(f"{run.Text!r} -> {run.Style.HyperlinkAddress}")None 安全性
Text 始终是一个 str (永不 None;;默认是 ""). Start 并且 End 可能是 None 用于在程序化创建的运行中,在它们被附加到 RichText. Style 始终存在。.
另见
- RichText::拥有的父节点
TextRuns - TextStyle::用于…的格式属性
TextRun - Properties::基类
- 开发者指南