RichText — Aspose.Note FOSS for Python API Reference
คลาส: RichText
Properties: aspose.note Properties: from aspose.note import RichText Properties: CompositeNode
RichText เป็นบล็อกของข้อความที่มีการจัดรูปแบบภายใน OutlineElement, TableCell, หรือ Title. มันเปิดเผยเนื้อหาข้อความธรรมดาเต็มรูปแบบผ่าน .Text และส่วนของการจัดรูปแบบแยกส่วนผ่าน .Runs.
Properties
| Properties | Properties | Properties | Properties |
|---|---|---|---|
Text | str | Properties | สตริงข้อความธรรมดาเต็มรูปแบบ (ทุกรันต่อเนื่องกัน) |
Runs | list[TextRun] | Properties | รายการลำดับของส่วนที่จัดรูปแบบแยกกัน |
FontSize | `float | None` | Properties |
Tags | list[NoteTag] | Properties | แท็ก OneNote ที่แนบกับบล็อกข้อความนี้ |
สืบทอดจาก CompositeNode / Node
| Properties | Properties |
|---|---|
ParentNode | โหนดที่บรรจุ (OutlineElement, TableCell, Title) |
Document | เอกสารราก |
Properties
Properties
rt.Append(text: str, style: TextStyle | None = None) -> RichTextเพิ่มรันข้อความใหม่พร้อมสไตล์ที่เป็นตัวเลือก คืนค่า self เพื่อการเชื่อมต่อ ทำงานในหน่วยความจำ; การเปลี่ยนแปลงไม่สามารถบันทึกกลับไปยัง .one.
from aspose.note import Document, RichText
doc = Document("MyNotes.one")
first_rt = doc.GetChildNodes(RichText)[0]
first_rt.Append(" [reviewed]")Replace(old_value, new_value)
rt.Replace(old_value: str, new_value: str) -> Noneแทนที่ทุกการปรากฏของ old_value ด้วย new_value ทั่วทุกรัน ทำงานในหน่วยความจำ.
from aspose.note import Document, RichText
doc = Document("MyNotes.one")
for rt in doc.GetChildNodes(RichText):
rt.Replace("TODO", "DONE")Accept(visitor)
rt.Accept(visitor: DocumentVisitor) -> NoneProperties VisitRichTextStart(rt) และ VisitRichTextEnd(rt) บนผู้เยี่ยมชม.
TextRun
แต่ละองค์ประกอบของ RichText.Runs เป็น TextRun:
| Properties | Properties | Properties |
|---|---|---|
Text | str | ข้อความส่วน |
Style | TextStyle | คุณสมบัติการจัดรูปแบบสำหรับส่วนนี้ |
Start | `int | None` |
End | `int | None` |
TextStyle
TextRun.Style เป็น TextStyle พร้อมคุณสมบัติดังต่อไปนี้:
| Properties | Properties | Properties |
|---|---|---|
Bold | bool | Properties |
Italic | bool | Properties |
Underline | bool | Properties |
Strikethrough | bool | Properties |
Superscript | bool | Properties |
Subscript | bool | Properties |
FontName | `str | None` |
FontSize | `float | None` |
FontColor | `int | None` |
Highlight | `int | None` |
Language | `int | None` |
IsHyperlink | bool | ว่าการรันนี้เป็นไฮเปอร์ลิงก์หรือไม่ |
HyperlinkAddress | `str | None` |
ตัวอย่างการใช้งาน
ดึงข้อความธรรมดาทั้งหมด
from aspose.note import Document, RichText
doc = Document("MyNotes.one")
for rt in doc.GetChildNodes(RichText):
if rt.Text:
print(rt.Text)ตรวจสอบรันทั้งหมดพร้อมการจัดรูปแบบ
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 = [a for a, v in [
("bold", s.IsBold), ("italic", s.IsItalic),
("underline", s.IsUnderline), ("strike", s.IsStrikethrough),
] if v]
label = ", ".join(attrs) or "plain"
print(f" [{label}] {run.Text!r}")สกัดลิงก์
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}")ค้นหาข้อความหนาทั้งหมด
from aspose.note import Document, RichText
doc = Document("MyNotes.one")
bold_segments = [
run.Text for rt in doc.GetChildNodes(RichText)
for run in rt.TextRuns
if run.Style.IsBold and run.Text.strip()
]
print(bold_segments)อ่านแท็ก
from aspose.note import Document, RichText
doc = Document("MyNotes.one")
for rt in doc.GetChildNodes(RichText):
for tag in rt.Tags:
print(f"Tag: {tag.label!r} on text: {rt.Text.strip()!r}")ความปลอดภัยจาก None
Text เป็นเสมอ a str (ไม่เคย None). Runs เป็นรายการเสมอ (อาจว่างเปล่า). FontSize, FontColor, Highlight, Language, HyperlinkAddress สามารถเป็น None.
ดูเพิ่มเติม
- Properties: บรรพบุรุษของ RichText
- TextRun: ส่วนที่จัดรูปแบบเป็นรายบุคคล
- TextStyle: คุณสมบัติการจัดรูปแบบ
- NoteTag: แท็กบนข้อความ
- คู่มือผู้พัฒนา Text Extraction
- How-to: ดึงข้อความจาก OneNote (KB)
- Blog: ดึงข้อความจาก OneNote ใน Python