{ "cells": [ { "cell_type": "markdown", "id": "22a849cc", "metadata": {}, "source": [ "# Microsoft Excel\n", "\n", "The `UnstructuredExcelLoader` is used to load `Microsoft Excel` files. The loader works with both `.xlsx` and `.xls` files. The page content will be the raw text of the Excel file. If you use the loader in `\"elements\"` mode, an HTML representation of the Excel file will be available in the document metadata under the `text_as_html` key." ] }, { "cell_type": "code", "execution_count": 1, "id": "e6616e3a", "metadata": {}, "outputs": [], "source": [ "from langchain_community.document_loaders import UnstructuredExcelLoader" ] }, { "cell_type": "code", "execution_count": 2, "id": "a654e4d9", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Document(page_content='\\n \\n \\n Team\\n Location\\n Stanley Cups\\n \\n \\n Blues\\n STL\\n 1\\n \\n \\n Flyers\\n PHI\\n 2\\n \\n \\n Maple Leafs\\n TOR\\n 13\\n \\n \\n', metadata={'source': 'example_data/stanley-cups.xlsx', 'filename': 'stanley-cups.xlsx', 'file_directory': 'example_data', 'filetype': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'page_number': 1, 'page_name': 'Stanley Cups', 'text_as_html': '\\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n
TeamLocationStanley Cups
BluesSTL1
FlyersPHI2
Maple LeafsTOR13
', 'category': 'Table'})" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "loader = UnstructuredExcelLoader(\"example_data/stanley-cups.xlsx\", mode=\"elements\")\n", "docs = loader.load()\n", "docs[0]" ] }, { "cell_type": "markdown", "id": "729ab1a2", "metadata": {}, "source": [ "## Using Azure AI Document Intelligence\n", "\n", ">[Azure AI Document Intelligence](https://aka.ms/doc-intelligence) (formerly known as `Azure Form Recognizer`) is machine-learning \n", ">based service that extracts texts (including handwriting), tables, document structures (e.g., titles, section headings, etc.) and key-value-pairs from\n", ">digital or scanned PDFs, images, Office and HTML files.\n", ">\n", ">Document Intelligence supports `PDF`, `JPEG/JPG`, `PNG`, `BMP`, `TIFF`, `HEIF`, `DOCX`, `XLSX`, `PPTX` and `HTML`.\n", "\n", "This current implementation of a loader using `Document Intelligence` can incorporate content page-wise and turn it into LangChain documents. The default output format is markdown, which can be easily chained with `MarkdownHeaderTextSplitter` for semantic document chunking. You can also use `mode=\"single\"` or `mode=\"page\"` to return pure texts in a single page or document split by page.\n" ] }, { "cell_type": "markdown", "id": "fbe5c77d", "metadata": {}, "source": [ "### Prerequisite\n", "\n", "An Azure AI Document Intelligence resource in one of the 3 preview regions: **East US**, **West US2**, **West Europe** - follow [this document](https://learn.microsoft.com/azure/ai-services/document-intelligence/create-document-intelligence-resource?view=doc-intel-4.0.0) to create one if you don't have. You will be passing `` and `` as parameters to the loader." ] }, { "cell_type": "code", "execution_count": null, "id": "fda529f8", "metadata": {}, "outputs": [], "source": [ "%pip install --upgrade --quiet langchain langchain-community azure-ai-documentintelligence" ] }, { "cell_type": "code", "execution_count": null, "id": "aa008547", "metadata": {}, "outputs": [], "source": [ "from langchain_community.document_loaders import AzureAIDocumentIntelligenceLoader\n", "\n", "file_path = \"\"\n", "endpoint = \"\"\n", "key = \"\"\n", "loader = AzureAIDocumentIntelligenceLoader(\n", " api_endpoint=endpoint, api_key=key, file_path=file_path, api_model=\"prebuilt-layout\"\n", ")\n", "\n", "documents = loader.load()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.13" } }, "nbformat": 4, "nbformat_minor": 5 }