如何加载 Microsoft Office 文件
Microsoft Office 生产力软件套件包括 Microsoft Word、Microsoft Excel、Microsoft PowerPoint、Microsoft Outlook 和 Microsoft OneNote。它适用于 Microsoft Windows 和 macOS 操作系统,也适用于 Android 和 iOS。
本文介绍如何将常用的文件格式(包括 DOCX
、XLSX
和 PPTX
文档)加载到 LangChain Document 对象中,以便我们在下游使用。
使用 AzureAIDocumentIntelligenceLoader 加载 DOCX、XLSX、PPTX
Azure AI 文档智能(以前称为 Azure 表单识别器
)是一种基于机器学习的服务,可从数字或扫描的 PDF、图像、Office 和 HTML 文件中提取文本(包括手写文本)、表格、文档结构(例如,标题、章节标题等)和键值对。文档智能支持 PDF
、JPEG/JPG
、PNG
、BMP
、TIFF
、HEIF
、DOCX
、XLSX
、PPTX
和 HTML
。
此使用 文档智能
的加载器的当前实现可以按页面合并内容,并将其转换为 LangChain 文档。默认输出格式是 markdown,可以很容易地与 MarkdownHeaderTextSplitter
链接,以进行语义文档分块。您也可以使用 mode="single"
或 mode="page"
返回纯文本,按单页或文档页面拆分。
先决条件
在 3 个预览区域之一中拥有 Azure AI 文档智能资源:美国东部、美国西部 2、西欧 - 如果您没有,请按照此文档创建一个。您将把 <endpoint>
和 <key>
作为参数传递给加载器。
%pip install --upgrade --quiet langchain langchain-community azure-ai-documentintelligence
from langchain_community.document_loaders import AzureAIDocumentIntelligenceLoader
file_path = "<filepath>"
endpoint = "<endpoint>"
key = "<key>"
loader = AzureAIDocumentIntelligenceLoader(
api_endpoint=endpoint, api_key=key, file_path=file_path, api_model="prebuilt-layout"
)
documents = loader.load()