AS AgentScopeAPI 手册 / API Reference
类class agentscope.rag

ExcelParser

class ExcelParser(ParserBase)
源码Source agentscope/rag/_parser/_excel.py:197–553

Excel 解析器,把私有文档转化为可检索的知识。位于 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_typeslist[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.

参数Parameters
名称Name类型Type说明Description
include_sheet_names默认default Trueboolinclude sheet names(类型 `bool`)。Whether to prepend each sheet's name as a header.
include_cell_coordinates默认default Falseboolinclude cell coordinates(类型 `bool`)。Whether to include cell coordinates (e.g. `[A1]`) in the rendered table.
include_image默认default Falseboolinclude 图像(类型 `bool`)。Whether to extract and include embedded images. Requires `openpyxl`.
separate_sheet默认default Falseboolseparate 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.
异常Raises
  • 当`ValueError`:If`table_format`是不`"markdown"`时抛出 `Exception`。`ValueError`: If `table_format` is not `"markdown"`
  • 可能抛出 `Exception`。or `"json"`.
源码Source 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.

源码Source agentscope/rag/_parser/_excel.py:227

方法详情Method Detail

supported_extensions

def supported_extensions() -> list[str]

返回[".xlsx", ".xls"]。

Return [".xlsx", ".xls"].

返回Returns list[str]
返回str列表。Returns a list of str.
源码Source agentscope/rag/_parser/_excel.py:233–235

parse

async def parse(file: bytes | str, filename: str) -> list[Section]
async

执行解析相关操作。

Parse an Excel file into a list of :class:Section objects.

参数Parameters
名称Name类型Type说明Description
filebytes | str文件(类型 `bytes | str`)。Either the raw Excel bytes, or a filesystem path to the Excel file.
filenamestrfilename(类型 `str`)。The source filename, copied into each Section's :attr:`Section.source`.
返回Returns list[Section]
返回Section列表。`list[Section]`:
异常Raises
  • 可能抛出 `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.
源码Source agentscope/rag/_parser/_excel.py:278–363
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.