# 05. Excel

### Excel <a href="#excel" id="excel"></a>

`UnstructuredExcelLoader Is` `Microsoft Excel` Used to load files.

This loader works on both .xlsx and .xls files. The page content will be the raw text of the Excel file.

When using the loader in "elements" mode, an HTML representation of the Excel file is provided under the text\_as\_html key in the document metadata.

Copy

```
# installation
# !pip install -qU langchain-community unstructured openpyxl
```

Copy

```
from langchain_community.document_loaders import UnstructuredExcelLoader

# UnstructuredExcelLoader generation
loader = UnstructuredExcelLoader("./data/titanic.xlsx", mode="elements")

# load document
docs = loader.load()

# Output document length
print(len(docs))
```

Verify that it is loaded as one document.

Copy

```
page_content stores the data for each row, and text_as_html in metadata stores the data for each row in HTML format.
```

Copy

```
# print document
print(docs[0].page_content[:200])
```

Copy

```
PassengerId
Survived
Pclass
Name
Sex
Age
SibSp
Parch
Ticket
Fare
Cabin
Embarked


1
0
3
Braund, Mr. Owen Harris
male
22
1
0
A/5 21171
7.25

S


2
1
1
Cumings, Mrs. John Bradley (Florence Briggs Tha
```

Copy

```
# metadata of text_as_html output of power
print(docs[0].metadata["text_as_html"][:1000])
```

#### DataFrameLoader <a href="#dataframeloader" id="dataframeloader"></a>

* Just like a CSV file, we use the read\_excel() function to load an Excel file, create it as a DataFrame, and then load it.

Copy

```
import pandas as pd

# Excel read file
df = pd.read_excel("./data/titanic.xlsx")
```

Copy

```
from langchain_community.document_loaders import DataFrameLoader

# Setting up a data frame loader, specifying page content columns
loader = DataFrameLoader(df, page_content_column="Name")

# Load Document
docs = loader.load()

# Data Output
print(docs[0].page_content)

# Output metadata
print(docs[0].metadata)
```

Copy

```
Braund, Mr. Owen Harris
{'PassengerId': 1, 'Survived': 0, 'Pclass': 3, 'Sex': 'male', 'Age': 22.0, 'SibSp': 1, 'Parch': 0, 'Ticket': 'A/5 21171', 'Fare': 7.25, 'Cabin': nan, 'Embarked': 'S'}
```
