> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-zh.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# Microsoft PowerPoint 集成

> 使用 LangChain Python 与 Microsoft PowerPoint 文档加载器集成。

> [Microsoft PowerPoint](https://en.wikipedia.org/wiki/Microsoft_PowerPoint) 是微软公司开发的演示文稿程序。

本文介绍如何将 `Microsoft PowerPoint` 文档加载为我们可在下游使用的文档格式。

有关在本地设置 Unstructured 的更多说明（包括设置所需的系统依赖项），请参阅 [Unstructured](/oss/python/integrations/providers/unstructured/)。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
# 安装包
pip install unstructured
pip install python-magic
pip install python-pptx
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_community.document_loaders import UnstructuredPowerPointLoader

loader = UnstructuredPowerPointLoader("./example_data/fake-power-point.pptx")

data = loader.load()

data
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
[Document(page_content='添加项目符号幻灯片\n\n查找项目符号幻灯片布局\n\n使用 _TextFrame.text 添加第一个项目符号\n\n使用 _TextFrame.add_paragraph() 添加后续项目符号\n\n这里有很多文本！\n\n这里是文本框中的一些文本！', metadata={'source': './example_data/fake-power-point.pptx'})]
```

### 保留元素

在底层，`Unstructured` 会为不同的文本块创建不同的“元素”。默认情况下我们会将它们合并在一起，但您可以通过指定 `mode="elements"` 轻松保留这种分离。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
loader = UnstructuredPowerPointLoader(
    "./example_data/fake-power-point.pptx", mode="elements"
)

data = loader.load()

data[0]
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
Document(page_content='添加项目符号幻灯片', metadata={'source': './example_data/fake-power-point.pptx', 'category_depth': 0, 'file_directory': './example_data', 'filename': 'fake-power-point.pptx', 'last_modified': '2023-12-19T13:42:18', 'page_number': 1, 'languages': ['eng'], 'filetype': 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'category': 'Title'})
```

## 使用 Azure AI 文档智能

> [Azure AI 文档智能](https://aka.ms/doc-intelligence)（原名 `Azure 表单识别器`）是一种基于机器学习的服务，可从数字或扫描的 PDF、图像、Office 和 HTML 文件中提取文本（包括手写内容）、表格、文档结构（例如标题、章节标题等）和键值对。
>
> 文档智能支持 `PDF`、`JPEG/JPG`、`PNG`、`BMP`、`TIFF`、`HEIF`、`DOCX`、`XLSX`、`PPTX` 和 `HTML`。

当前使用 `文档智能` 的加载器实现可以按页整合内容，并将其转换为 LangChain 文档。默认输出格式为 Markdown，可轻松与 `MarkdownHeaderTextSplitter` 链式结合，用于语义文档分块。您也可以使用 `mode="single"` 或 `mode="page"` 来返回单页的纯文本或按页分割的文档。

## 先决条件

一个位于以下三个预览区域之一的 Azure AI 文档智能资源：**美国东部**、**美国西部 2**、**西欧**——如果您还没有，请按照[此文档](https://learn.microsoft.com/azure/ai-services/document-intelligence/create-document-intelligence-resource?view=doc-intel-4.0.0)创建一个。您需要将 `<endpoint>` 和 `<key>` 作为参数传递给加载器。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
pip install -qU  langchain langchain-community azure-ai-documentintelligence
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_community.document_loaders import AzureAIDocumentIntelligenceLoader

file_path = "<文件路径>"
endpoint = "<端点>"
key = "<密钥>"
loader = AzureAIDocumentIntelligenceLoader(
    api_endpoint=endpoint, api_key=key, file_path=file_path, api_model="prebuilt-layout"
)

documents = loader.load()
```

***

<div className="source-links">
  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/i18n\zh-CN\oss\python\integrations\document_loaders\microsoft_powerpoint.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>

  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>
</div>
