#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os

import openpyxl

p = '/Users/liuxinyuan/Desktop/hermas输入-工作台数据库/2024和2025历史数据/2025全年订单.xlsx'
wb = openpyxl.load_workbook(p, read_only=True, data_only=True)
for ws in wb.worksheets:
    rows = list(ws.iter_rows(values_only=True))
    if not rows:
        continue
    # 找表头行（含“客户”）
    hi = next((i for i, r in enumerate(rows[:6]) if any('客户' in str(c) for c in r if c)), None)
    if hi is None:
        continue
    head = [str(c) if c is not None else '' for c in rows[hi]]
    print('\n== sheet', ws.title, '｜表头:', head[:14])
    hits = [r for r in rows[hi + 1:] if '艾德' in ' '.join(str(c) for c in r if c is not None)
            and '艾德范思' not in ' '.join(str(c) for c in r if c is not None)]
    print('  命中', len(hits))
    for r in hits[:20]:
        d = {head[i]: r[i] for i in range(min(len(head), len(r))) if head[i]}
        keep = {k: v for k, v in d.items() if k in ('合同日期', '单据编号', '客户', '销售员', '物料编码', '物料名称', '数量', '单价', '金额', '价税合计', '单据类型')}
        print('   ', keep)
