# -*- coding: utf-8 -*- import pandas as pd kd = pd.read_excel('物料清单正查_1.xlsx', sheet_name='树形单据体') kd = kd[kd['子项物料编码'].notna()].copy() kd['code'] = kd['子项物料编码'].astype(str).str.strip() kd['name'] = kd['物料名称'].astype(str).str.strip() kd['lv'] = kd['BOM层级'].astype(str).str.strip() out = [] # 金蝶 1.11.2 直接子件(深度4)中,位置在 LORA 组件附近(1.11.2.45~1.11.2.50)的 d4 = kd[kd['lv'].apply(lambda x: x.startswith('1.11.2.') and len(x.split('.')) == 4)].copy() d4['seq'] = d4['lv'].apply(lambda x: int(x.split('.')[-1])) d4 = d4.sort_values('seq') out.append("=== 1.11.2 全部62个直接子件(按序号)===") for _, r in d4.iterrows(): out.append(f" {r['lv']} {r['code']} {r['name']}") with open('kd_3420d.txt', 'w', encoding='utf-8') as f: f.write('\n'.join(out)) print("done")