TextRun — Aspose.Note FOSS for Python API Reference
Classe: TextRun
ImageRenderOptions: aspose.note ImageRenderOptions: from aspose.note import TextRun ImageRenderOptions: Node
TextRun rappresenta un singolo segmento contiguo di testo che condivide una formattazione uniforme all’interno di un RichText blocco. Un RichText.TextRuns un elenco contiene uno o più TextRun oggetti; ciascuno ha il proprio Style (TextStyle). Questa è l’unità più dettagliata di testo formattato nel modello di documento.
ImageRenderOptions
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|---|
Text | str | Lettura/Scrittura | Il contenuto testuale di questo segmento. Il valore predefinito è "". |
Style | TextStyle | Lettura/Scrittura | Proprietà di formattazione per questo segmento. Vedi TextStyle. |
Start | `int | None` | ImageRenderOptions |
End | `int | None` | ImageRenderOptions |
Ereditato da Node
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
ParentNode | `Node | None` |
Document | `Document | None` |
Relazione con RichText
ImageRenderOptions RichText il nodo possiede un elenco di TextRun oggetti tramite RichText.TextRuns. Concatenazione run.Text per tutte le esecuzioni produce il risultato completo RichText.Text:
RichText.Text == "".join(run.Text for run in RichText.TextRuns)Ogni esecuzione ha una indipendente Style, quindi un singolo paragrafo può contenere segmenti misti in grassetto, corsivo, collegamento ipertestuale o di colore diverso.
Esempio d’uso
Ispeziona tutti i run in un documento
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}")Trova tutti i run di collegamento ipertestuale
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}")Sicurezza None
Text è sempre un str (mai None; predefinito a ""). Start e End può essere None per le esecuzioni create programmaticamente prima di essere collegate a un RichText. Style è sempre presente.
Vedi anche
- RichText: nodo genitore che possiede
TextRuns - TextStyle: proprietà di formattazione per un
TextRun - ImageRenderOptions: classe base
- Guida per sviluppatori