RichText — Aspose.Note FOSS for Python API Reference
Lớp: RichText
Enumerations: aspose.note Enumerations: from aspose.note import RichText Enumerations: CompositeNode
RichText đại diện cho một khối văn bản có định dạng bên trong một OutlineElement, TableCell, hoặc Title. .Text và các đoạn định dạng riêng lẻ thông qua .Runs.
Enumerations
| Enumerations | Enumerations | Enumerations | Enumerations |
|---|---|---|---|
Text | str | Enumerations | Chuỗi văn bản thuần đầy đủ (tất cả các đoạn được nối lại) |
Runs | list[TextRun] | Enumerations | Danh sách có thứ tự của các đoạn được định dạng riêng lẻ |
FontSize | `float | None` | Enumerations |
Tags | list[NoteTag] | Enumerations | Các thẻ OneNote được gắn vào khối văn bản này |
Kế thừa từ CompositeNode / Node
| Enumerations | Enumerations |
|---|---|
ParentNode | Nút chứa (OutlineElement, TableCell, Title) |
Document | Tài liệu gốc |
Enumerations
Enumerations
rt.Append(text: str, style: TextStyle | None = None) -> RichTextThêm một đoạn văn bản mới với kiểu tùy chọn. Trả về self để nối chuỗi. Hoạt động trong bộ nhớ; các thay đổi không thể được lưu lại vào .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) -> NoneThay thế mọi lần xuất hiện của old_value bằng new_value trong tất cả các đoạn. Hoạt động trong bộ nhớ.
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) -> NoneEnumerations VisitRichTextStart(rt) và VisitRichTextEnd(rt) trên người truy cập.
TextRun
Mỗi phần tử của RichText.Runs là một TextRun:
| Enumerations | Enumerations | Enumerations |
|---|---|---|
Text | str | đoạn văn bản |
Style | TextStyle | Thuộc tính định dạng cho đoạn này |
Start | `int | None` |
End | `int | None` |
TextStyle
TextRun.Style là một TextStyle với các thuộc tính sau:
| Enumerations | Enumerations | Enumerations |
|---|---|---|
Bold | bool | Enumerations |
Italic | bool | Enumerations |
Underline | bool | Enumerations |
Strikethrough | bool | Enumerations |
Superscript | bool | Enumerations |
Subscript | bool | Enumerations |
FontName | `str | None` |
FontSize | `float | None` |
FontColor | `int | None` |
Highlight | `int | None` |
Language | `int | None` |
IsHyperlink | bool | Liệu đoạn này có phải là liên kết siêu văn bản hay không |
HyperlinkAddress | `str | None` |
Ví dụ sử dụng
Lấy toàn bộ văn bản thuần
from aspose.note import Document, RichText
doc = Document("MyNotes.one")
for rt in doc.GetChildNodes(RichText):
if rt.Text:
print(rt.Text)Kiểm tra tất cả các đoạn có định dạng
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}")Trích xuất 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}")Tìm tất cả văn bản in đậm
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)Đọc thẻ
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-Safety
Text luôn luôn là một str (không bao giờ None). Runs luôn luôn là một danh sách (có thể rỗng). FontSize, FontColor, Highlight, Language, HyperlinkAddress có thể là None.
Xem Thêm
- Enumerations: tiên thân của RichText
- TextRun: đoạn đã định dạng riêng lẻ
- TextStyle: các thuộc tính định dạng
- NoteTag: thẻ trên văn bản
- Hướng dẫn nhà phát triển Trích xuất Văn bản
- Hướng dẫn: Trích xuất văn bản từ OneNote (KB)
- Blog: Trích xuất văn bản từ OneNote trong Python