feat: ExcelParser 基础(workbook/sheet 读取 + source_uri)

This commit is contained in:
lhl
2026-08-08 16:50:24 +08:00
parent 35d845fd21
commit df9427c76e
5 changed files with 68 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
"""Parser Agent:输入资料解析层。"""
+20
View File
@@ -0,0 +1,20 @@
from __future__ import annotations
from pathlib import Path
from typing import Any
from openpyxl import load_workbook
from openpyxl.worksheet.worksheet import Worksheet
def open_workbook(path: str | Path):
"""普通模式打开 .xlsx(保留公式/样式/批注),.xls 报错。"""
path = Path(path)
if path.suffix.lower() != ".xlsx":
raise ValueError(f"不支持的 Excel 格式: {path.suffix}")
return load_workbook(path)
def sheet_matrix(ws: Worksheet) -> list[list[Any]]:
"""整表矩形值(含 None),保留到 max_column。"""
return [[cell.value for cell in row] for row in ws.iter_rows()]
+3
View File
@@ -0,0 +1,3 @@
def build_source_uri(file_name: str, sheet_name: str, cell_ref: str) -> str:
"""单元格来源 URIfile.xlsx#SheetName!CellRef"""
return f"{file_name}#{sheet_name}!{cell_ref}"