วิธีตรวจสอบแท็ก 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`

กรองแท็กที่เสร็จสมบูรณ์กับแท็กที่ค้างอยู่

แท็กที่ถูกทำเครื่องหมายแล้ว (เช่น กล่องทำเครื่องหมาย “To Do”) มีค่า non-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 method 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 เพื่อระบุประเภทแท็กโดยโปรแกรม.


Related Resources:

 ภาษาไทย