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” チェックボックスのようなもの)は、非-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 サポートされていないため、作成されたタグはファイルに永続化できません。.
よくある問題
タグが見つかりません(ドキュメントは空の Tags リストを返します): すべてではありません .one ファイルにタグが含まれています。コードのトラブルシューティングを行う前に、元のドキュメントに Microsoft OneNote で表示可能なタグがあることを確認してください。.
tag.Label は空文字列です: 一部のタグ形状にはファイルメタデータにテキストラベルがありません。使用してください tag.Icon タグタイプをプログラムで識別するために。.
関連リソース: