# -*- coding: utf-8 -*- import openpyxl, glob, os docs = r'C:\Users\jcxiong\Documents\Codex\MyProject\trafficAudit\docs' for name in ['生成_货运量排名.xlsx', '生成_周转量排名.xlsx']: f = glob.glob(os.path.join(docs, name))[0] wb = openpyxl.load_workbook(f) ws = wb[wb.sheetnames[0]] print('='*30, name, 'dims', ws.max_row, ws.max_column) for r in [1, 2, 3, 4, 23, 24, 25, 26]: vals = [str(ws.cell(r,c).value)[:26] if ws.cell(r,c).value is not None else '' for c in range(1, ws.max_column+1)] nonempty = [(i+1, v) for i, v in enumerate(vals) if v] print(r, '|', ' | '.join(f'c{c}={v}' for c, v in nonempty))