feat: 实现模板解析,自动识别 {{占位符}}

This commit is contained in:
MikiVL
2026-05-05 05:52:42 +08:00
parent 18de4f9f47
commit 1f51665e42
4 changed files with 62 additions and 2 deletions
+24 -1
View File
@@ -1 +1,24 @@
# placeholder
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):
m = PLACEHOLDER_RE.search(cell.value)
if m:
placeholders.append({
"name": m.group(1),
"sheet": sheet_name,
"cell": cell.coordinate,
})
return {"sheets": sheets, "placeholders": placeholders}