mirror of
https://github.com/Mintplex-Labs/langchain-python.git
synced 2026-07-19 13:26:32 -04:00
a97e4252e3
# Unstructured Excel Loader
Adds an `UnstructuredExcelLoader` class for `.xlsx` and `.xls` files.
Works with `unstructured>=0.6.7`. A plain text representation of the
Excel file will be available under the `page_content` attribute in the
doc. If you use the loader in `"elements"` mode, an HTML representation
of the Excel file will be available under the `text_as_html` metadata
key. Each sheet in the Excel document is its own document.
### Testing
```python
from langchain.document_loaders import UnstructuredExcelLoader
loader = UnstructuredExcelLoader(
"example_data/stanley-cups.xlsx",
mode="elements"
)
docs = loader.load()
```
## Who can review?
@hwchase17
@eyurtsev
23 lines
766 B
Python
23 lines
766 B
Python
"""Loader that loads Microsoft Excel files."""
|
|
from typing import Any, List
|
|
|
|
from langchain.document_loaders.unstructured import (
|
|
UnstructuredFileLoader,
|
|
validate_unstructured_version,
|
|
)
|
|
|
|
|
|
class UnstructuredExcelLoader(UnstructuredFileLoader):
|
|
"""Loader that uses unstructured to load Microsoft Excel files."""
|
|
|
|
def __init__(
|
|
self, file_path: str, mode: str = "single", **unstructured_kwargs: Any
|
|
):
|
|
validate_unstructured_version(min_unstructured_version="0.6.7")
|
|
super().__init__(file_path=file_path, mode=mode, **unstructured_kwargs)
|
|
|
|
def _get_elements(self) -> List:
|
|
from unstructured.partition.xlsx import partition_xlsx
|
|
|
|
return partition_xlsx(filename=self.file_path, **self.unstructured_kwargs)
|