Files
onion-dmp/check_excel.py
2026-04-08 14:52:09 +08:00

70 lines
2.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import openpyxl
wb = openpyxl.load_workbook('家庭教育档案-天数.xlsx')
ws = wb.active
print('✓ 所有表头列表')
print('=' * 80)
for i in range(1, ws.max_column + 1):
cell = ws.cell(1, i)
col_letter = chr(64 + i) if i <= 26 else chr(64 + i // 26) + chr(64 + i % 26)
print(f'{i:2d} ({col_letter:2s}): {cell.value}')
print('\n' + '=' * 80)
print('✓ C列家庭角色全部唯一值')
print('=' * 80)
c_values = {}
for row in range(2, ws.max_row + 1):
val = str(ws[f'C{row}'].value).strip() if ws[f'C{row}'].value else ''
if val:
c_values[val] = c_values.get(val, 0) + 1
for val, count in sorted(c_values.items()):
print(f' {val:15s} (出现 {count:3d} 次)')
print('\n' + '=' * 80)
print('✓ D列文化程度全部唯一值')
print('=' * 80)
d_values = {}
for row in range(2, ws.max_row + 1):
val = str(ws[f'D{row}'].value).strip() if ws[f'D{row}'].value else ''
if val:
d_values[val] = d_values.get(val, 0) + 1
for val, count in sorted(d_values.items()):
print(f' {val:20s} (出现 {count:3d} 次)')
print('\n' + '=' * 80)
print('✓ U列孩子学习成绩全部唯一值')
print('=' * 80)
u_values = {}
for row in range(2, ws.max_row + 1):
val = str(ws[f'U{row}'].value).strip() if ws[f'U{row}'].value else ''
if val:
u_values[val] = u_values.get(val, 0) + 1
for val, count in sorted(u_values.items()):
print(f' {val:15s} (出现 {count:3d} 次)')
print('\n' + '=' * 80)
print('✓ 寻找性格/特征相关列...')
print('=' * 80)
found = False
for i in range(1, ws.max_column + 1):
header = str(ws.cell(1, i).value).lower() if ws.cell(1, i).value else ''
if '性格' in header or '特征' in header or '个性' in header or '性质' in header:
col_letter = chr(64 + i) if i <= 26 else chr(64 + i // 26) + chr(64 + i % 26)
print(f'✓ 找到Column {i} ({col_letter}): {ws.cell(1, i).value}')
# 取样
values = {}
for row in range(2, min(100, ws.max_row + 1)):
val = str(ws[f'{col_letter}{row}'].value).strip() if ws[f'{col_letter}{row}'].value else ''
if val:
values[val] = values.get(val, 0) + 1
for val, count in sorted(values.items()):
print(f' {val:30s} (出现 {count:3d} 次)')
found = True
if not found:
print('✗ 未找到明确的性格/特征列')
print('请检查以下可能的列...')