TextRun

Lớp: TextRun

Enumerations: aspose.note Enumerations: from aspose.note import TextRun Enumerations: Node

TextRun đại diện cho một đoạn văn bản liên tục duy nhất có định dạng đồng nhất trong một RichText khối. A RichText.TextRuns danh sách chứa một hoặc nhiều TextRun đối tượng; mỗi có riêng Style (TextStyle). Đây là đơn vị chi tiết nhất của văn bản được định dạng trong mô hình tài liệu.


Enumerations

NameTypeAccessDescription
TextstrRead/WriteGets or sets the text.
StyleTextStyleRead/WriteGets or sets the style.

Kế thừa từ Node

EnumerationsEnumerationsEnumerations
ParentNode`NodeNone`
Document`DocumentNone`

Mối quan hệ với RichText

Enumerations RichText nút sở hữu một danh sách của TextRun đối tượng thông qua RichText.TextRuns. Ghép nối run.Text đối với mọi lần chạy cho ra toàn bộ RichText.Text:

RichText.Text == "".join(run.Text for run in RichText.TextRuns)

Mỗi lần chạy mang một tính độc lập Style, vì vậy một đoạn văn duy nhất có thể chứa các đoạn in đậm, in nghiêng, siêu liên kết, hoặc các đoạn có màu khác nhau.


Ví dụ sử dụng

Kiểm tra tất cả các đoạn trong tài liệu

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}")

Tìm tất cả các đoạn siêu liên kết

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-Safety

Text luôn là một str (không bao giờ None; mặc định là ""). StartEnd có thể là None cho các run được tạo lập trình trước khi chúng được gắn vào một RichText. Style luôn tồn tại.


Xem Thêm

 Tiếng Việt