كيفية فحص علامات OneNote في Python
يتيح OneNote للمستخدمين إضافة تعليقات توضيحية إلى المحتوى باستخدام العلامات الملونة: النجوم، مربعات الاختيار، العلامات المهمة، والتسميات المخصصة. يتيح Aspose.Note FOSS for Python هذه التعليقات على شكل كائنات NoteTag على عقد RichText، Image، AttachedFile، وTable عبر خاصية .Tags الخاصة بها. يوضح هذا الدليل كيفية قراءتها.
دليل خطوة بخطوة
الخطوة 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} Icon={tag.Icon} 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: جمع جميع العلامات عبر المستند
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
| Property | Type | Description |
|---|---|---|
Icon | int | None | معرف شكل العلامة الرقمية (نجمة، مربع اختيار، سهم، إلخ.) |
Label | str | None | سلسلة تسمية قابلة للقراءة من قبل الإنسان (مثال: "Important"، "To Do") |
FontColor | int | None | لون النص كعدد صحيح ARGB |
Highlight | int | None | لون التظليل كعدد صحيح ARGB |
CreationTime | datetime | None | متى تم إنشاء العلامة |
CompletedTime | datetime | None | متى تم إكمال العلامة (None إذا لم تُكمل) |
Status | TagStatus | TagStatus.Completed إذا اكتملت، وإلا TagStatus.Open |
تصفية العلامات المكتملة مقابل المعلقة
العلامات التي تم وضع علامة عليها (مثل مربعات الاختيار “To Do”) لديها حقل غير None CompletedTime:
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}")إنشاء NoteTag (في الذاكرة)
طريقة المصنع NoteTag.CreateYellowStar() تنشئ عقدة علامة يمكنك إرفاقها بالمحتوى الجديد في الذاكرة:
from aspose.note import NoteTag
tag = NoteTag.CreateYellowStar()
print(f"Created tag: Icon={tag.Icon} Label={tag.Label!r}")إنشاء الذاكرة الداخلية مفيد لتوافق API. بما أن الكتابة مرة أخرى إلى
.oneغير مدعومة، لا يمكن حفظ العلامات التي تم إنشاؤها إلى ملف.
مشكلات شائعة
لم يتم العثور على علامات (المستند يُعيد قوائم علامات فارغة): ليست كل ملفات .one تحتوي على علامات. تحقق من أن المستند المصدر يحتوي على علامات مرئية في Microsoft OneNote قبل استكشاف الأخطاء في الشيفرة.
tag.Label هو سلسلة فارغة: بعض أشكال العلامات لا تحتوي على تسمية نصية في بيانات ملف التعريف. استخدم tag.Icon لتحديد نوع العلامة برمجياً.
الموارد ذات الصلة: