diff --git a/core/parser.py b/core/parser.py index 1208001..323c0cf 100644 --- a/core/parser.py +++ b/core/parser.py @@ -163,8 +163,8 @@ class K3VoucherParser: if cy < y_lower - 100 or cy > y_debit_val: continue - # x坐标:科目代码通常在表格中间区域 - if cx < 1500 or cx > 2600: + # x坐标:科目代码通常在表格中间偏左区域 + if cx < 1200 or cx > 2600: continue t = text.strip() @@ -185,6 +185,8 @@ class K3VoucherParser: # 提取名称 — 按用户规则:取最后一个横杠之后的文字 name = t[m.end():].lstrip('--—= ') + # 记录原始inline文本是否含横杠(判断完整性用) + inline_has_dash = max(name.rfind('-'), name.rfind('-'), name.rfind('—')) >= 0 name = re.sub(r'[\d.\-—=]+$', '', name).strip() name = name.lstrip('-—-=') @@ -198,8 +200,8 @@ class K3VoucherParser: # 去重:优先保留带完整名称的行 if code_part in code_map: existing = codes[code_map[code_part]] - # 已有名称为空,而新行有名称 → 更新 - if (not existing['name'] or len(existing['name']) < 2) and len(name) >= 2: + # 新名称的原文本含横杠(更完整)→ 更新 + if inline_has_dash or ((not existing['name'] or len(existing['name']) < 2) and len(name) >= 2): existing['name'] = name existing['y_pos'] = cy existing['x_pos'] = cx