Commit d0dfc667 by zhouhaibao

fix(renovation-parser): 修复 Excel 合并单元格续行数据被跳过的问题

- 新增上一行门店名称和园区店缓存,实现合并单元格续行值继承
- 将 contract_amount 和 accept_date 提取提前至跳过判断之前
- 修改跳过条件:门店/园区店均为空且合同金额为 0 时才跳过
- 缓存更新时空值不覆盖,避免错误继承
1 parent 25f89c5c
......@@ -85,6 +85,10 @@ class RenovationDetailParser:
try:
ws = wb[wb.sheetnames[0]]
details = []
# Excel 合并单元格:openpyxl 只有合并区域左上角有值,后续行返回 None。
# 这里缓存上一行的值,续行向上继承,避免合并区域内有合同金额的行被跳过。
last_store_name = ''
last_park_store = ''
for row in ws.iter_rows(min_row=DATA_ROW_START, max_col=MAX_COL, values_only=True):
def cell(col):
idx = col - 1
......@@ -92,14 +96,30 @@ class RenovationDetailParser:
store_name = _s(cell(COL_STORE_NAME))
park_store = _s(cell(COL_PARK_STORE))
# 门店名称与系统园区店名称均为空的行视为空行/合计行,跳过
if not store_name and not park_store:
contract_amount = _to_num(cell(COL_CONTRACT))
accept_date = cell(COL_ACCEPT_DATE)
# 合并单元格续行:门店名称/园区店为空 → 继承上一行
if not store_name and last_store_name:
store_name = last_store_name
if not park_store and last_park_store:
park_store = last_park_store
# 跳过条件:门店名称/园区店都空 **且** 合同金额也为 0 → 空行/合计行
if not store_name and not park_store and contract_amount == 0:
continue
# 缓存(空值不覆盖)
if store_name:
last_store_name = store_name
if park_store:
last_park_store = park_store
details.append({
'store_name': store_name,
'park_store_name': park_store,
'contract_amount': _to_num(cell(COL_CONTRACT)),
'accept_date': cell(COL_ACCEPT_DATE),
'contract_amount': contract_amount,
'accept_date': accept_date,
})
finally:
wb.close()
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!