Cara Memeriksa Tag OneNote di Python
OneNote memungkinkan pengguna memberi anotasi pada konten dengan tag berwarna: bintang, kotak centang, bendera penting, dan label khusus. Aspose.Note FOSS untuk Python mengekspos anotasi ini sebagai objek NoteTag pada node RichText, Image, AttachedFile, dan Table melalui properti .Tags mereka. Panduan ini menunjukkan cara membacanya.
Panduan Langkah-demi-Langkah
Langkah 1: Instal Aspose.Note FOSS untuk Python
pip install aspose-noteLangkah 2: Muat File .one
from aspose.note import Document
doc = Document("TaggedNotes.one")
print(f"Pages: {len(list(doc))}")Langkah 3: Temukan Tag pada Node RichText
Sebagian besar tag terlampir pada blok teks:
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}")Langkah 4: Temukan Tag pada Gambar
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}")Langkah 5: Temukan Tag pada Tabel
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]}")Langkah 6: Kumpulkan Semua Tag di Seluruh Dokumen
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)Referensi Properti NoteTag
| Property | Type | Description |
|---|---|---|
Icon | int | None | Pengidentifikasi bentuk tag numerik (bintang, kotak centang, panah, dll.) |
Label | str | None | String label yang dapat dibaca manusia (misalnya "Important", "To Do") |
FontColor | int | None | Warna teks sebagai integer ARGB |
Highlight | int | None | Warna sorotan sebagai integer ARGB |
CreationTime | datetime | None | Kapan tag dibuat |
CompletedTime | datetime | None | Kapan tag selesai (None jika belum selesai) |
Status | TagStatus | TagStatus.Completed jika selesai, jika tidak TagStatus.Open |
Filter Tag Selesai vs Tag Tertunda
Tag yang telah dicentang (seperti kotak centang “To Do”) memiliki bidang non-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}")Buat NoteTag (In-Memory)
Metode pabrik NoteTag.CreateYellowStar() membuat node tag yang dapat Anda lampirkan ke konten baru dalam memori:
from aspose.note import NoteTag
tag = NoteTag.CreateYellowStar()
print(f"Created tag: Icon={tag.Icon} Label={tag.Label!r}")Pembuatan dalam memori berguna untuk kompatibilitas API. Karena penulisan kembali ke
.onetidak didukung, tag yang dibuat tidak dapat dipertahankan ke file.
Masalah Umum
Tidak ada tag yang ditemukan (dokumen mengembalikan daftar Tag kosong): Tidak semua file .one berisi tag. Verifikasi bahwa dokumen sumber memiliki tag yang terlihat di Microsoft OneNote sebelum memecahkan masalah kode.
tag.Label adalah string kosong: Beberapa bentuk tag tidak memiliki label teks dalam metadata file. Gunakan tag.Icon untuk mengidentifikasi tipe tag secara programatik.
Sumber Daya Terkait: