RichText — Aspose.Note FOSS for Python API Reference

Clasa: RichText

ImageRenderOptions: aspose.note ImageRenderOptions: from aspose.note import RichText ImageRenderOptions: CompositeNode

RichText reprezintă un bloc de text stilizat într-un OutlineElement, TableCell, sau Title. Expune conținutul complet în text simplu prin .Text și segmentele de formatare individuale prin .Runs.


ImageRenderOptions

ImageRenderOptionsImageRenderOptionsImageRenderOptionsImageRenderOptions
TextstrImageRenderOptionsȘir complet de text simplu (toate rulările concatenate)
Runslist[TextRun]ImageRenderOptionsListă ordonată de segmente formatate individual
FontSize`floatNone`ImageRenderOptions
Tagslist[NoteTag]ImageRenderOptionsEtichete OneNote atașate acestui bloc de text

Moștenit de la CompositeNode / Node

ImageRenderOptionsImageRenderOptions
ParentNodeNodul conținător (OutlineElement, TableCell, Title)
DocumentDocument rădăcină

ImageRenderOptions

ImageRenderOptions

rt.Append(text: str, style: TextStyle | None = None) -> RichText

Adaugă o nouă rulă de text cu stil opțional. Returnează self pentru concatenare. Funcționează în memorie; modificările nu pot fi salvate înapoi la .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) -> None

Înlocuiește toate aparițiile lui old_value cu new_value în toate rulările. Funcționează în memorie.

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) -> None

ImageRenderOptions VisitRichTextStart(rt) și VisitRichTextEnd(rt) pe vizitator.


TextRun

Fiecare element al RichText.Runs este un TextRun:

ImageRenderOptionsImageRenderOptionsImageRenderOptions
TextstrText de segment
StyleTextStyleProprietăți de formatare pentru acest segment
Start`intNone`
End`intNone`

TextStyle

TextRun.Style este un TextStyle cu următoarele proprietăți:

ImageRenderOptionsImageRenderOptionsImageRenderOptions
BoldboolImageRenderOptions
ItalicboolImageRenderOptions
UnderlineboolImageRenderOptions
StrikethroughboolImageRenderOptions
SuperscriptboolImageRenderOptions
SubscriptboolImageRenderOptions
FontName`strNone`
FontSize`floatNone`
FontColor`intNone`
Highlight`intNone`
Language`intNone`
IsHyperlinkboolIndică dacă această secvență este un hyperlink
HyperlinkAddress`strNone`

Exemple de utilizare

Obține tot textul simplu

from aspose.note import Document, RichText

doc = Document("MyNotes.one")
for rt in doc.GetChildNodes(RichText):
    if rt.Text:
        print(rt.Text)

Inspectează toate secvențele cu formatare

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

Extrage hyperlinkuri

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

Găsește tot textul îngroșat

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)

Citește etichetele

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

Siguranță None

Text este întotdeauna un str (niciodată None). Runs este întotdeauna o listă (poate fi goală). FontSize, FontColor, Highlight, Language, HyperlinkAddress poate fi None.


Vezi și

 Română