Cum să inspectați etichetele OneNote în Python

Cum să inspectați etichetele OneNote în Python

OneNote permite utilizatorilor să adnoteze conținutul cu etichete colorate: stele, casete de bifare, semnale importante și etichete personalizate. Aspose.Note FOSS pentru Python expune aceste adnotări ca NoteTag obiecte pe RichText, Image, Table, și OutlineElement noduri. Acest ghid arată cum să le citiți.


Ghid pas cu pas

Pasul 1: Instalați Aspose.Note FOSS pentru Python

pip install aspose-note

Pasul 2: Încărcați fișierul .one

from aspose.note import Document

doc = Document("TaggedNotes.one")
print(f"Pages: {len(list(doc))}")

Pasul 3: Găsiți etichetele pe nodurile RichText

Majoritatea etichetelor sunt atașate blocurilor de text:

from aspose.note import Document, RichText

doc = Document("TaggedNotes.one")
for rt in doc.GetChildNodes(RichText):
    for tag in rt.Tags:
        print(f"[RichText] label={tag.label!r}  shape={tag.shape}  text={rt.Text.strip()!r}")

Pasul 4: Găsiți etichetele pe imagini

from aspose.note import Document, Image

doc = Document("TaggedNotes.one")
for img in doc.GetChildNodes(Image):
    for tag in img.Tags:
        print(f"[Image] label={tag.label!r}  filename={img.FileName!r}")

Pasul 5: Găsiți etichetele pe tabele

from aspose.note import Document, Table

doc = Document("TaggedNotes.one")
for table in doc.GetChildNodes(Table):
    for tag in table.Tags:
        print(f"[Table] label={tag.label!r}  widths={[col.Width for col in table.Columns]}")

Pasul 6: Găsiți etichetele pe OutlineElements

from aspose.note import Document, OutlineElement

doc = Document("TaggedNotes.one")
for oe in doc.GetChildNodes(OutlineElement):
    for tag in oe.Tags:
        print(f"[OutlineElement] label={tag.label!r}  completed={tag.completed}")

Pasul 7: Colectați toate etichetele din document

from aspose.note import Document, RichText, Image, Table, OutlineElement

doc = Document("TaggedNotes.one")
all_tags = []

for rt in doc.GetChildNodes(RichText):
    for tag in rt.Tags:
        all_tags.append({"type": "RichText", "label": tag.label,
                         "completed": tag.completed, "text": rt.Text.strip()})
for img in doc.GetChildNodes(Image):
    for tag in img.Tags:
        all_tags.append({"type": "Image", "label": tag.label,
                         "completed": tag.completed, "file": img.FileName})
for table in doc.GetChildNodes(Table):
    for tag in table.Tags:
        all_tags.append({"type": "Table", "label": tag.label,
                         "completed": tag.completed})

print(f"Total tagged items: {len(all_tags)}")
for item in all_tags:
    print(item)

Referință proprietăți NoteTag

ProprietateTipDescriere
shapeN/AIdentificator de formă a etichetei (stea, casetă de bifare, săgeată, etc.)
labelstrȘir de etichetă lizibil pentru oameni (de ex. "Important", "To Do")
text_colorintCuloarea textului ca întreg ARGB
highlight_colorintCuloarea evidențierii ca întreg ARGB
created`intNone`
completed`intNone`

Filtrați etichetele finalizate vs cele în așteptare

Etichetele care au fost bifate (ca casetele de selectare „To Do”) au un câmp non-None completed câmp:

from aspose.note import Document, RichText

doc = Document("TaggedNotes.one")
pending, done = [], []

for rt in doc.GetChildNodes(RichText):
    for tag in rt.Tags:
        item = {"label": tag.label, "text": rt.Text.strip()}
        if tag.completed is None:
            pending.append(item)
        else:
            done.append(item)

print(f"Pending: {len(pending)}  Done: {len(done)}")
for p in pending:
    print(f"  [ ] {p['label']}: {p['text']!r}")
for d in done:
    print(f"  [x] {d['label']}: {d['text']!r}")

Creați un NoteTag (în memorie)

Metoda de fabrică NoteTag.CreateYellowStar() creează un nod de etichetă pe care îl poți atașa la conținut nou în memorie:

from aspose.note import NoteTag

tag = NoteTag.CreateYellowStar()
print(f"Created tag: shape={tag.shape}  label={tag.label!r}")

Crearea în memorie este utilă pentru compatibilitatea API. Deoarece scrierea înapoi la .one nu este suportată, etichetele create nu pot fi persistate în fișier.


Probleme comune

Nu s-au găsit etichete (documentul returnează liste de Etichete goale): Nu toate .one fișiere conțin etichete. Verificați că documentul sursă are etichetele vizibile în Microsoft OneNote înainte de a depana codul.

tag.label este un șir gol: Unele forme de etichetă nu au o etichetă text în metadatele fișierului. Utilizați tag.shape pentru a identifica tipul etichetei programatic.


Resurse conexe:

 Română