AttachedFile — Aspose.Note FOSS for Python API Reference
คลาส: AttachedFile
Properties: aspose.note Properties: from aspose.note import AttachedFile Properties: CompositeNode
AttachedFile เป็นไฟล์ไบนารีที่ถูกฝังอยู่ภายในส่วนของ OneNote. มันเป็นลูกของ OutlineElement. ข้อมูลไฟล์ดิบพร้อมให้เข้าถึงผ่าน the 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. ไม่มี API ที่จะเปลี่ยนข้อมูลไฟล์ที่ฝังอยู่ใน v26.3.1. - Properties: การบันทึกเอกสารที่มี
AttachedFilenodes to 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 - คู่มือผู้พัฒนา