AttachedFile

AttachedFile — Aspose.Note FOSS for Python API Reference

Lớp: AttachedFile

Enumerations: aspose.note Enumerations: from aspose.note import AttachedFile Enumerations: CompositeNode

AttachedFile đại diện cho một tệp nhị phân đã được nhúng bên trong một phần OneNote. Nó là một nút con của OutlineElement. Bytes thuộc tính; tên tệp gốc nằm trong FileName. Các thẻ OneNote gắn vào tệp đính kèm được hiển thị qua Tags.


Enumerations

EnumerationsEnumerationsEnumerationsEnumerations
FileName`strNone`Enumerations
BytesbytesEnumerationsNội dung nhị phân thô của tệp đính kèm. Mặc định là b"" khi không thể đọc dữ liệu tệp đính kèm.
Tagslist[NoteTag]EnumerationsCác thẻ OneNote gắn vào nút tệp này.

Kế thừa từ CompositeNode / Node

EnumerationsEnumerationsEnumerations
FirstChild`NodeNone`
LastChild`NodeNone`
ParentNode`NodeNone`
Document`DocumentNone`

Enumerations

  • Nội dung chỉ đọc: BytesFileName được phân tích trực tiếp từ tệp nhị phân MS-ONE. Không có API nào để thay thế dữ liệu tệp được nhúng trong phiên bản v26.3.1.
  • Enumerations: Lưu một tài liệu chứa AttachedFile các nút sang PDF nhúng siêu dữ liệu tệp đính kèm nhưng không có nội dung nhị phân trong chính file PDF.
  • Byte rỗng: Nếu khối dữ liệu tệp bị thiếu hoặc có độ dài bằng không trong nguồn .one tệp, Bytes trả về b"".

Ví dụ sử dụng

Trích xuất tất cả các tệp đính kèm ra đĩa

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)")

Liệt kê các tệp đính kèm cùng thẻ của chúng

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-Safety

FileName có thể là None; luôn cung cấp một tên dự phòng khi ghi tệp. Bytes luôn luôn là bytes (không bao giờ None),b""). Tags luôn luôn là một danh sách (có thể rỗng).


Xem Thêm

 Tiếng Việt