RichText — Aspose.Note FOSS for Python API Reference
Classe: RichText
ImageRenderOptions: aspose.note ImageRenderOptions: from aspose.note import RichText ImageRenderOptions: CompositeNode
RichText rappresenta un blocco di testo formattato all’interno di un OutlineElement, TableCell, o Title. Espone il contenuto completo in plain‑text via .Text e segmenti di formattazione individuali tramite .Runs.
ImageRenderOptions
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|---|
Text | str | ImageRenderOptions | Stringa di testo semplice completa (tutte le esecuzioni concatenate) |
Runs | list[TextRun] | ImageRenderOptions | Elenco ordinato di segmenti formattati individualmente |
FontSize | `float | None` | ImageRenderOptions |
Tags | list[NoteTag] | ImageRenderOptions | Tag di OneNote allegati a questo blocco di testo |
Ereditato da CompositeNode / Node
| ImageRenderOptions | ImageRenderOptions |
|---|---|
ParentNode | Nodo contenente (OutlineElement, TableCell, Title) |
Document | Documento radice |
ImageRenderOptions
ImageRenderOptions
rt.Append(text: str, style: TextStyle | None = None) -> RichTextAggiunge un nuovo run di testo con stile opzionale. Restituisce self per concatenazione. Funziona in memoria; le modifiche non possono essere salvate nuovamente su .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) -> NoneSostituisce tutte le occorrenze di old_value con new_value in tutte le esecuzioni. Funziona in memoria.
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) -> NoneImageRenderOptions VisitRichTextStart(rt) e VisitRichTextEnd(rt) sul visitatore.
TextRun
Ogni elemento di RichText.Runs è un TextRun:
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
Text | str | Testo del segmento |
Style | TextStyle | Proprietà di formattazione per questo segmento |
Start | `int | None` |
End | `int | None` |
TextStyle
TextRun.Style è un TextStyle con le seguenti proprietà:
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
Bold | bool | ImageRenderOptions |
Italic | bool | ImageRenderOptions |
Underline | bool | ImageRenderOptions |
Strikethrough | bool | ImageRenderOptions |
Superscript | bool | ImageRenderOptions |
Subscript | bool | ImageRenderOptions |
FontName | `str | None` |
FontSize | `float | None` |
FontColor | `int | None` |
Highlight | `int | None` |
Language | `int | None` |
IsHyperlink | bool | Se questa sequenza è un collegamento ipertestuale |
HyperlinkAddress | `str | None` |
Esempi d’uso
Ottieni tutto il testo semplice
from aspose.note import Document, RichText
doc = Document("MyNotes.one")
for rt in doc.GetChildNodes(RichText):
if rt.Text:
print(rt.Text)Ispeziona tutte le sequenze con formattazione
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}")Estrai i collegamenti ipertestuali
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}")Trova tutto il testo in grassetto
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)Leggi i tag
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}")Sicurezza None
Text è sempre un str (mai None). Runs è sempre una lista (può essere vuota). FontSize, FontColor, Highlight, Language, HyperlinkAddress può essere None.
Vedi anche
- ImageRenderOptions: antenato di RichText
- TextRun: segmento formattato individuale
- TextStyle: proprietà di formattazione
- NoteTag: tag sul testo
- Guida per sviluppatori all’estrazione del testo
- Guida: estrarre testo da OneNote (KB)
- Blog: estrarre testo da OneNote in Python