Каїлейт DOC fajlovi u Pythonu

Каїлейт DOC fajlovi u Pythonu

Aspose.Words FOSS for Python đọc các tệp .doc Word 97-2003 qua ̋DocFileReader∂ . Hướng dẫn này cho thấy cách tải tƣờng t›. doc™ từ đĩa, dòng và bộ đệm byte.


Tải từ đường dẫn tệp

Cách tiếp cận đơn giản nhất sử dụng constructor Document, tự động chọn trình đọc DOC:

import aspose.words_foss as aw

doc = aw.Document("legacy-report.doc")
print(f"Loaded {len(doc.sections)} section(s)")

Nạp từ một dòng chảy

Đối với các ứng dụng web xử lý tải lên file:

import aspose.words_foss as aw

with open("uploaded.doc", "rb") as stream:
    doc = aw.Document(stream)
    text = doc.get_text()
    print(text[:200])

Tải từ Bytes

Khi nội dung tập tin đã có trong bộ nhớ:

from aspose.words_foss.doc_reader.doc_file_reader_core import DocFileReaderCore

data = read_from_database()  # returns bytes
reader = DocFileReaderCore()
reader.load_bytes(data)

Xem Thêm

  • DOC Reader Developer Guide (Hướng dẫn cho nhà phát triển)
  • Cách tải tệp DOCX
  • Câu hỏi thường gặp
 Tiếng Việt