agentscope.ragExcelParser
class ExcelParser(ParserBase)
agentscope/rag/_parser/_excel.py:197–553Excel 解析器,把私有文档转化为可检索的知识。位于 agentscope.rag 包,继承自 ParserBase。核心成员包括 supported_extensions、parse。
Each sheet is scanned for tabular data and (optionally) images.
Tables are rendered as Markdown pipe-tables or JSON arrays; images
are emitted as standalone :class:DataBlock sections, including on
sheets without cell values. Header-only tables are preserved.
When separate_sheet=True each sheet becomes a batch of
sections that never intermix with other sheets, making it possible
for a downstream chunker to keep sheets apart.
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
def __init__(include_sheet_names: bool = True, include_cell_coordinates: bool = False, include_image: bool = False, sep… | 初始化 `ExcelParser` 实例。 Initialize the Excel parser. |
属性摘要Attribute Summary
| 属性Attribute | 类型Type | 说明Description | 值Value |
|---|---|---|---|
supported_media_types | list[str] | `supported_media_types` 字段。 | ['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.ms-excel'] |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
def supported_extensions() -> list[str] | 返回`[".xlsx", ".xls"]`。 Return ``[".xlsx", ".xls"]``. |
async def parse(file: bytes | str, filename: str) -> list[Section]async | 执行解析相关操作。 Parse an Excel file into a list of :class:`Section` objects. |
构造器详情Constructor Detail
ExcelParser
def __init__(include_sheet_names: bool = True, include_cell_coordinates: bool = False, include_image: bool = False, separate_sheet: bool = False, table_format: Literal['markdown', 'json'] = 'markdown') -> None
初始化 ExcelParser 实例。
Initialize the Excel parser.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
include_sheet_names默认default True | bool | include sheet names(类型 `bool`)。Whether to prepend each sheet's name as a header. |
include_cell_coordinates默认default False | bool | include cell coordinates(类型 `bool`)。Whether to include cell coordinates (e.g. `[A1]`) in the rendered table. |
include_image默认default False | bool | include 图像(类型 `bool`)。Whether to extract and include embedded images. Requires `openpyxl`. |
separate_sheet默认default False | bool | separate sheet(类型 `bool`)。If `True`, images and table text from different sheets are never combined into the same section. table_format (`Literal["markdown", "json"]`, defaults to `"markdown"`): How to render tables. |
table_format默认default 'markdown' | Literal['markdown', 'json'] | table 格式(类型 `Literal['markdown', 'json']`)。The table format. |
- 当`ValueError`:If`table_format`是不`"markdown"`时抛出 `Exception`。`ValueError`: If `table_format` is not `"markdown"`
- 可能抛出 `Exception`。or `"json"`.
agentscope/rag/_parser/_excel.py:237–276属性详情Attribute Detail
supported_media_types
list[str] = ['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.ms-excel']supported_media_types 字段。声明为 list[str]。
The supported media types field.
agentscope/rag/_parser/_excel.py:227方法详情Method Detail
supported_extensions
def supported_extensions() -> list[str]
返回[".xlsx", ".xls"]。
Return [".xlsx", ".xls"].
agentscope/rag/_parser/_excel.py:233–235parse
async def parse(file: bytes | str, filename: str) -> list[Section]
执行解析相关操作。
Parse an Excel file into a list of :class:Section objects.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
file | bytes | str | 文件(类型 `bytes | str`)。Either the raw Excel bytes, or a filesystem path to the Excel file. |
filename | str | filename(类型 `str`)。The source filename, copied into each Section's :attr:`Section.source`. |
- 可能抛出 `Exception`。`FileNotFoundError`: If `file` is a `str` pointing to
- 可能抛出 `Exception`。a path that does not exist.
- 可能抛出 `Exception`。`ImportError`: If :mod:`pandas` is not installed.
- 可能抛出 `Exception`。`ValueError`: If the workbook or any worksheet cannot be parsed.
agentscope/rag/_parser/_excel.py:278–363