איך לבדוק תגים של OneNote ב-Python

איך לבדוק תגים של OneNote ב-Python

OneNote מאפשר למשתמשים להוסיף הערות לתוכן עם תגיות צבעוניות: כוכבים, תיבות סימון, דגלים חשובים ותוויות מותאמות. Aspose.Note FOSS עבור Python חושף את ההערות האלה כ NoteTag אובייקטים ב RichText, Image, Table, ו OutlineElement צמתים. מדריך זה מראה כיצד לקרוא אותם.


מדריך שלב‑אחר‑שלב

שלב 1: התקן Aspose.Note FOSS עבור Python

pip install aspose-note

שלב 2: טען את קובץ ה-.one

from aspose.note import Document

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

שלב 3: מצא תגים בצמתים של RichText

רוב התגים מצורפים לחסימות טקסט:

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

שלב 4: מצא תגים בתמונות

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

שלב 5: מצא תגים בטבלאות

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

שלב 6: מצא תגים ב-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}")

שלב 7: אסוף את כל התגים במסמך

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)

התייחסות למאפייני NoteTag

מאפייןסוגתיאור
shapeN/Aמזהה צורת תגית (כוכב, תיבת סימון, חץ, וכו')
labelstrמחרוזת תווית קריאה לבן אדם (לדוגמה. "Important", "To Do")
text_colorintצבע טקסט כמספר שלם ARGB
highlight_colorintצבע הדגשה כמספר שלם ARGB
created`intNone`
completed`intNone`

סינון תגים שהושלמו מול תגים ממתינים

תגיות שסומנו (כמו תיבות הסימון “לעשות”) כוללות ערך שאינו-None completed שדה:

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

צור NoteTag (בזיכרון)

שיטת ה‑factory NoteTag.CreateYellowStar() יוצרת צומת תג שאתה יכול לצרף לתוכן חדש בזיכרון:

from aspose.note import NoteTag

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

יצירה בזיכרון היא שימושית לתאימות API. מכיוון שהכתיבה חזרה ל .one אינו נתמך, לא ניתן לשמור תגים שנוצרו לקובץ.


בעיות נפוצות

לא נמצאו תגים (המסמך מחזיר רשימות תגים ריקות): לא כולם .one קבצים מכילים תגים. ודא שלמסמך המקור יש תגים גלויים ב-Microsoft OneNote לפני ניתוח תקלות בקוד.

tag.label הוא מחרוזת ריקה: חלק מצורות התגים אינם כוללים תווית טקסט במטא-נתוני הקובץ. השתמש tag.shape כדי לזהות את סוג התג באופן תכנותי.


משאבים קשורים:

 עברית