如何加载 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 Document Intelligence(以前称为 Azure Form Recognizer)是一种基于机器学习的服务,可从数字或扫描的 PDF、图像、Office 和 HTML 文件中提取文本(包括手写)、表格、文档结构(例如标题、章节标题等)以及键值对。Document Intelligence 支持 PDF、JPEG/JPG、PNG、BMP、TIFF、HEIF、DOCX、XLSX、PPTX 和 HTML。
使用 Document Intelligence 的此当前实现的加载器可以逐页地整合内容,并将其转换为 LangChain 文档。默认输出格式是 markdown,可以轻松地与 MarkdownHeaderTextSplitter 结合进行语义文档分块。您还可以使用 mode="single" 或 mode="page" 来返回纯文本,分为单页或按页拆分的文档。
前提条件
在以下 3 个预览区域之一中拥有一个 Azure AI Document Intelligence 资源:East US、West US2、West Europe - 如果您还没有,请遵循此文档进行创建。您将把 <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()