excel-batch-editor/python/xl_parser.py
MikiVL 70a56ede36 添加 macOS 安装包打包支持
- 重命名 parser.py → xl_parser.py 避免与 Python 3.9 stdlib 命名冲突
- 添加 PyInstaller spec 文件用于构建独立 Python 可执行文件
- 配置 electron-builder:extraResources 打包 Python binary、asarUnpack better-sqlite3
- 新增 build:python 和 dist 脚本,一键生成 DMG 安装包
- 更新测试:对齐新 fixture 结构和重命名后的模块

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-05 19:44:01 +08:00

25 lines
807 B
Python

import re
from openpyxl import load_workbook
PLACEHOLDER_RE = re.compile(r"\{\{(.+?)\}\}")
def parse_template(file_path: str) -> dict:
wb = load_workbook(file_path, data_only=False)
sheets = wb.sheetnames
placeholders = []
for sheet_name in sheets:
ws = wb[sheet_name]
for row in ws.iter_rows():
for cell in row:
if cell.value and isinstance(cell.value, str):
matches = PLACEHOLDER_RE.findall(cell.value)
for name in matches:
placeholders.append({
"name": name,
"sheet": sheet_name,
"cell": cell.coordinate,
})
return {"sheets": sheets, "placeholders": placeholders}