Python에서 OneNote 태그를 검사하는 방법
OneNote는 사용자가 색상 태그(별, 체크박스, 중요 플래그, 사용자 정의 레이블)로 콘텐츠에 주석을 달 수 있게 합니다. Aspose.Note FOSS for Python는 이러한 주석을 다음과 같이 노출합니다. NoteTag 객체는 RichText, Image, AttachedFile, 및 Table 노드들은 그들의 .Tags 속성을 통해 접근합니다. 이 가이드는 이를 읽는 방법을 보여줍니다.
단계별 가이드
단계 1: Aspose.Note FOSS for 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 속성 참조
| 속성 | 유형 | 설명 |
|---|---|---|
Icon | `int | None` |
Label | `str | None` |
FontColor | `int | None` |
Highlight | `int | None` |
CreationTime | `datetime | None` |
CompletedTime | `datetime | None` |
Status | TagStatus | TagStatus.Completed 완료된 경우, 그렇지 않으면 TagStatus.Open |
완료된 태그와 보류 중인 태그 필터링
체크된 태그(예: “To Do” 체크박스)는 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}")NoteTag 생성 (메모리 내)
팩토리 메서드 NoteTag.CreateYellowStar() 새 콘텐츠에 메모리 내에서 첨부할 수 있는 태그 노드를 생성합니다:
from aspose.note import NoteTag
tag = NoteTag.CreateYellowStar()
print(f"Created tag: Icon={tag.Icon} Label={tag.Label!r}")메모리 내 생성은 API 호환성에 유용합니다. 다시 쓰기가 지원되지 않으므로 .one 지원되지 않으며, 생성된 태그는 파일에 저장될 수 없습니다.
Common Issues
태그를 찾을 수 없습니다 (문서가 빈 Tags 목록을 반환함): 모두가 아님 .one 파일에 태그가 포함되어 있습니다. 코드를 문제 해결하기 전에 원본 문서에 Microsoft OneNote에서 보이는 태그가 있는지 확인하십시오.
tag.Label 빈 문자열입니다: 일부 태그 형태는 파일 메타데이터에 텍스트 레이블이 없습니다. 사용 tag.Icon 태그 유형을 프로그래밍 방식으로 식별합니다.
관련 자료: