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

PropertiesPropertiesPropertiesProperties
TextstrRead/Writeเนื้อหาข้อความของส่วนนี้. ค่าเริ่มต้นคือ "".
StyleTextStyleRead/Writeคุณสมบัติการจัดรูปแบบสำหรับส่วนนี้. ดู TextStyle.
Start`intNone`Properties
End`intNone`Properties

สืบทอดจาก Node

PropertiesPropertiesProperties
ParentNode`NodeNone`
Document`DocumentNone`

ความสัมพันธ์กับ 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 จะเป็นเสมอ a str (ไม่เคย None; มีค่าเริ่มต้นเป็น ""). Start และ End อาจเป็น None สำหรับการทำงานที่สร้างโดยโปรแกรมก่อนที่มันจะถูกแนบกับ a RichText. Style จะปรากฏเสมอ.


ดูเพิ่มเติม

 ภาษาไทย