AttachedFile — Aspose.Note FOSS for Python API Reference
类:AttachedFile
Properties: aspose.note Properties: from aspose.note import AttachedFile Properties: CompositeNode
AttachedFile 表示已嵌入在 OneNote 区段中的二进制文件。它是 OutlineElement. Bytes 属性;原始文件名位于 FileName. OneNote 附加的标签通过以下方式公开: Tags.
Properties
| Properties | Properties | Properties | Properties |
|---|---|---|---|
FileName | `str | None` | Properties |
Bytes | bytes | Properties | 附件文件的原始二进制内容。默认值为 b"" 当无法读取附件数据时。. |
Tags | list[NoteTag] | Properties | 附加在此文件节点上的 OneNote 标签。. |
继承自 CompositeNode / Node
| Properties | Properties | Properties |
|---|---|---|
FirstChild | `Node | None` |
LastChild | `Node | None` |
ParentNode | `Node | None` |
Document | `Document | None` |
Properties
- 只读内容:
Bytes和FileName直接从 MS-ONE 二进制解析。v26.3.1 中没有 API 可替换嵌入的文件数据。. - Properties::保存包含
AttachedFilenodes to PDF 将附件元数据嵌入 PDF,但不在 PDF 本身中嵌入二进制内容。. - 空字节: 如果源文件中的数据块缺失或长度为零
.one文件,,Bytes返回b"".
使用示例
将所有附件提取到磁盘
import os
from aspose.note import Document, AttachedFile
doc = Document("MyNotes.one")
output_dir = "attachments"
os.makedirs(output_dir, exist_ok=True)
for af in doc.GetChildNodes(AttachedFile):
name = af.FileName or "unnamed_attachment"
dest = os.path.join(output_dir, name)
with open(dest, "wb") as f:
f.write(af.Bytes)
print(f"Saved: {dest} ({len(af.Bytes)} bytes)")列出附件及其标签
from aspose.note import Document, AttachedFile
doc = Document("MyNotes.one")
for af in doc.GetChildNodes(AttachedFile):
tag_labels = [t.label for t in af.Tags if t.label]
print(f"{af.FileName!r} tags={tag_labels} size={len(af.Bytes)}B")None 安全性
FileName 可能是 None; 在写入文件时始终提供备用名称。. Bytes 始终是 bytes (永不 None),b""). Tags 始终是一个列表(可能为空)。.
另见
- CompositeNode: 父类
- NoteTag: 附件上的标签
- OutlineElement: 容器用于
AttachedFile - 开发者指南