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
+20
View File
@@ -0,0 +1,20 @@
from openpyxl import Workbook
def new_workbook(sheets: dict[str, list[list]]) -> Workbook:
"""生成临时 Workbookkey=Sheet 名,value=gridcell 值)。"""
wb = Workbook()
wb.remove(wb.active)
for name, grid in sheets.items():
ws = wb.create_sheet(name)
for r, row in enumerate(grid, start=1):
for c, value in enumerate(row, start=1):
ws.cell(row=r, column=c, value=value)
return wb
def save_workbook(tmp_path, wb: Workbook) -> str:
"""落盘到 tmp_path 并返回路径字符串。"""
path = tmp_path / "source.xlsx"
wb.save(path)
return str(path)