Hoe OneNote-tags te inspecteren in Python
OneNote stelt gebruikers in staat om inhoud te annoteren met gekleurde tags: sterren, selectievakjes, belangrijke vlaggen en aangepaste labels. Aspose.Note FOSS voor Python maakt deze annotaties beschikbaar als NoteTag objecten op RichText, Image, AttachedFile, en Table knooppunten via hun .Tags eigenschap. Deze gids laat zien hoe je ze kunt lezen.
Stapsgewijze handleiding
Stap 1: Installeer Aspose.Note FOSS voor Python
pip install aspose-noteStap 2: Laad het .one-bestand
from aspose.note import Document
doc = Document("TaggedNotes.one")
print(f"Pages: {len(list(doc))}")Stap 3: Tags vinden op RichText‑knooppunten
De meeste tags zijn gekoppeld aan tekstblokken:
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} Icon={tag.Icon} text={rt.Text.strip()!r}")Stap 4: Tags vinden op afbeeldingen
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}")Stap 5: Tags vinden op tabellen
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]}")Stap 6: Alle tags in het document verzamelen
from aspose.note import Document, RichText, Image, Table
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,
"CompletedTime": tag.CompletedTime, "text": rt.Text.strip()})
for img in doc.GetChildNodes(Image):
for tag in img.Tags:
all_tags.append({"type": "Image", "Label": tag.Label,
"CompletedTime": tag.CompletedTime, "file": img.FileName})
for table in doc.GetChildNodes(Table):
for tag in table.Tags:
all_tags.append({"type": "Table", "Label": tag.Label,
"CompletedTime": tag.CompletedTime})
print(f"Total tagged items: {len(all_tags)}")
for item in all_tags:
print(item)NoteTag‑eigenschapreferentie
| Eigenschap | Type | Beschrijving |
|---|---|---|
Icon | `int | None` |
Label | `str | None` |
FontColor | `int | None` |
Highlight | `int | None` |
CreationTime | `datetime | None` |
CompletedTime | `datetime | None` |
Status | TagStatus | TagStatus.Completed indien voltooid, anders TagStatus.Open |
Voltooide versus openstaande tags filteren
Tags die zijn afgevinkt (zoals “To Do”-selectievakjes) hebben een non-None CompletedTime veld:
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.CompletedTime 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}")Een NoteTag maken (in‑memory)
De fabrieksmethode NoteTag.CreateYellowStar() maakt een tagknooppunt dat je kunt koppelen aan nieuwe inhoud in‑memory:
from aspose.note import NoteTag
tag = NoteTag.CreateYellowStar()
print(f"Created tag: Icon={tag.Icon} Label={tag.Label!r}")In‑memory creatie is nuttig voor API‑compatibiliteit. Aangezien terugschrijven naar .one niet wordt ondersteund, kunnen aangemaakte tags niet worden opgeslagen in een bestand.
Veelvoorkomende problemen
Geen tags gevonden (document retourneert lege Tags‑lijsten): Niet alle .one bestanden bevatten tags. Controleer of het brondocument tags bevat die zichtbaar zijn in Microsoft OneNote voordat je de code gaat troubleshooten.
tag.Label is een lege tekenreeks: Sommige tagvormen hebben geen tekstlabel in de bestandsmetadata. Gebruik tag.Icon om het tagtype programmatisch te identificeren.
Gerelateerde bronnen: