Microsoft Excel
UnstructuredExcelLoader
用於載入 Microsoft Excel
檔案。此載入器適用於 .xlsx
和 .xls
檔案。頁面內容將是 Excel 檔案的原始文字。如果您在 "elements"
模式下使用此載入器,則 Excel 檔案的 HTML 表示形式將可在文件元數據的 text_as_html
鍵下取得。
請參閱本指南,以取得有關在本地設定 Unstructured 的更多說明,包括設定所需的系統相依性。
%pip install --upgrade --quiet langchain-community unstructured openpyxl
from langchain_community.document_loaders import UnstructuredExcelLoader
loader = UnstructuredExcelLoader("./example_data/stanley-cups.xlsx", mode="elements")
docs = loader.load()
print(len(docs))
docs
API 參考:UnstructuredExcelLoader
4
[Document(page_content='Stanley Cups', metadata={'source': './example_data/stanley-cups.xlsx', 'file_directory': './example_data', 'filename': 'stanley-cups.xlsx', 'last_modified': '2023-12-19T13:42:18', 'page_name': 'Stanley Cups', 'page_number': 1, 'languages': ['eng'], 'filetype': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'category': 'Title'}),
Document(page_content='\n\n\nTeam\nLocation\nStanley Cups\n\n\nBlues\nSTL\n1\n\n\nFlyers\nPHI\n2\n\n\nMaple Leafs\nTOR\n13\n\n\n', metadata={'source': './example_data/stanley-cups.xlsx', 'file_directory': './example_data', 'filename': 'stanley-cups.xlsx', 'last_modified': '2023-12-19T13:42:18', 'page_name': 'Stanley Cups', 'page_number': 1, 'text_as_html': '<table border="1" class="dataframe">\n <tbody>\n <tr>\n <td>Team</td>\n <td>Location</td>\n <td>Stanley Cups</td>\n </tr>\n <tr>\n <td>Blues</td>\n <td>STL</td>\n <td>1</td>\n </tr>\n <tr>\n <td>Flyers</td>\n <td>PHI</td>\n <td>2</td>\n </tr>\n <tr>\n <td>Maple Leafs</td>\n <td>TOR</td>\n <td>13</td>\n </tr>\n </tbody>\n</table>', 'languages': ['eng'], 'parent_id': '17e9a90f9616f2abed8cf32b5bd3810d', 'filetype': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'category': 'Table'}),
Document(page_content='Stanley Cups Since 67', metadata={'source': './example_data/stanley-cups.xlsx', 'file_directory': './example_data', 'filename': 'stanley-cups.xlsx', 'last_modified': '2023-12-19T13:42:18', 'page_name': 'Stanley Cups Since 67', 'page_number': 2, 'languages': ['eng'], 'filetype': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'category': 'Title'}),
Document(page_content='\n\n\nTeam\nLocation\nStanley Cups\n\n\nBlues\nSTL\n1\n\n\nFlyers\nPHI\n2\n\n\nMaple Leafs\nTOR\n0\n\n\n', metadata={'source': './example_data/stanley-cups.xlsx', 'file_directory': './example_data', 'filename': 'stanley-cups.xlsx', 'last_modified': '2023-12-19T13:42:18', 'page_name': 'Stanley Cups Since 67', 'page_number': 2, 'text_as_html': '<table border="1" class="dataframe">\n <tbody>\n <tr>\n <td>Team</td>\n <td>Location</td>\n <td>Stanley Cups</td>\n </tr>\n <tr>\n <td>Blues</td>\n <td>STL</td>\n <td>1</td>\n </tr>\n <tr>\n <td>Flyers</td>\n <td>PHI</td>\n <td>2</td>\n </tr>\n <tr>\n <td>Maple Leafs</td>\n <td>TOR</td>\n <td>0</td>\n </tr>\n </tbody>\n</table>', 'languages': ['eng'], 'parent_id': 'ee34bd8c186b57e3530d5443ffa58122', 'filetype': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'category': 'Table'})]
使用 Azure AI 文件智慧
Azure AI 文件智慧(以前稱為
Azure Form Recognizer
)是一種基於機器學習的服務,可從數位或掃描的 PDF、圖像、Office 和 HTML 檔案中提取文本(包括手寫)、表格、文件結構(例如,標題、章節標題等)和鍵值對。文件智慧支援
JPEG/JPG
、PNG
、BMP
、TIFF
、HEIF
、DOCX
、XLSX
、PPTX
和HTML
。
目前使用 Document Intelligence
的載入器實作可以逐頁合併內容,並將其轉換為 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()