Cách Kiểm Tra Thẻ OneNote trong Python
OneNote cho phép người dùng chú thích nội dung bằng các thẻ màu: sao, hộp kiểm, cờ quan trọng và nhãn tùy chỉnh. Aspose.Note FOSS cho Python tiết lộ các chú thích này dưới dạng NoteTag đối tượng trên RichText, Image, AttachedFile, và Table các nút thông qua .Tags thuộc tính. Hướng dẫn này cho thấy cách đọc chúng.
Hướng Dẫn Từng Bước
Bước 1: Cài đặt Aspose.Note FOSS cho Python
pip install aspose-noteBước 2: Tải tệp .one
from aspose.note import Document
doc = Document("TaggedNotes.one")
print(f"Pages: {len(list(doc))}")Bước 3: Tìm Thẻ trên Các Nút RichText
Hầu hết các thẻ được gắn vào các khối văn bản:
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}")Bước 4: Tìm Thẻ trên Hình Ảnh
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}")Bước 5: Tìm Thẻ trên Bảng
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]}")Bước 6: Thu Thập Tất Cả Các Thẻ Trong Toàn Bộ Tài Liệu
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)Tham Khảo Thuộc Tính NoteTag
| Thuộc tính | Kiểu | Mô tả |
|---|---|---|
Icon | `int | None` |
Label | `str | None` |
FontColor | `int | None` |
Highlight | `int | None` |
CreationTime | `datetime | None` |
CompletedTime | `datetime | None` |
Status | TagStatus | TagStatus.Completed nếu đã hoàn thành, ngược lại TagStatus.Open |
Lọc Thẻ Đã Hoàn Thành và Thẻ Đang Chờ
Các thẻ đã được đánh dấu (như các hộp kiểm “To Do”) có một non-None CompletedTime trường:
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}")Tạo NoteTag (Trong Bộ Nhớ)
Phương thức factory NoteTag.CreateYellowStar() tạo một nút thẻ mà bạn có thể đính kèm vào nội dung mới trong bộ nhớ:
from aspose.note import NoteTag
tag = NoteTag.CreateYellowStar()
print(f"Created tag: Icon={tag.Icon} Label={tag.Label!r}")Việc tạo trong bộ nhớ hữu ích cho tính tương thích API. Vì không hỗ trợ ghi lại vào .one không được hỗ trợ, các thẻ đã tạo không thể được lưu lại vào tệp.
Common Issues
Không tìm thấy thẻ nào (tài liệu trả về danh sách Thẻ trống): Không phải tất cả .one các tệp chứa thẻ. Xác minh tài liệu nguồn có thẻ hiển thị trong Microsoft OneNote trước khi khắc phục sự cố mã.
tag.Label là một chuỗi rỗng: Một số hình dạng thẻ không có nhãn văn bản trong siêu dữ liệu tệp. Sử dụng tag.Icon để xác định loại thẻ một cách lập trình.
Tài nguyên liên quan: