Source code for langchain_community.document_loaders.excel

"""加载Microsoft Excel文件。"""
from pathlib import Path
from typing import Any, List, Union

from langchain_community.document_loaders.unstructured import (
    UnstructuredFileLoader,
    validate_unstructured_version,
)


[docs]class UnstructuredExcelLoader(UnstructuredFileLoader): """使用`Unstructured`加载Microsoft Excel文件。 像其他Unstructured加载器一样,UnstructuredExcelLoader可以在“single”和“elements”模式下使用。如果您在“elements”模式下使用加载器,则Excel文件中的每个工作表将成为一个Unstructured Table元素。如果您在“single”模式下使用加载器,则表的HTML表示将在文档元数据的“text_as_html”键中可用。 示例 -------- ```python from langchain_community.document_loaders.excel import UnstructuredExcelLoader loader = UnstructuredExcelLoader("stanley-cups.xlsx", mode="elements") docs = loader.load() ```"""
[docs] def __init__( self, file_path: Union[str, Path], mode: str = "single", **unstructured_kwargs: Any, ): """参数: file_path:Microsoft Excel文件的路径。 mode:在对文件进行分区时要使用的模式。有关更多信息,请参阅非结构化文档。可选。默认为"single"。 **unstructured_kwargs:要传递给非结构化的关键字参数。 """ 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)