import sys, io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
import openpyxl, importlib.util
from collections import Counter
P=r'D:\01.프로젝트\DB수집\작업파일\광역_사이트맵\충청남도\8.서산시\충청남도_서산시.xlsx'
spec=importlib.util.spec_from_file_location('chk', r'D:\01.프로젝트\DB수집\작업파일\광역_사이트맵\_검수체크.py')
chk=importlib.util.module_from_spec(spec); spec.loader.exec_module(chk)
n,issues=chk.inspect(P)
print(f'=== 구조검수: {"PASS" if not issues else "FAIL "+str(len(issues))+"건"} ({n}행) ===')
for x in issues: print('  X', x)
ws=openpyxl.load_workbook(P).active
data=[r for r in range(3,ws.max_row+1) if ws.cell(r,2).value not in (None,'')]
print('\n정렬 분포:')
for c,nm in [(4,'D'),(5,'E'),(6,'F'),(7,'G'),(11,'K')]:
    cnt=Counter((ws.cell(r,c).alignment.horizontal,ws.cell(r,c).alignment.vertical,ws.cell(r,c).alignment.wrap_text) for r in data)
    print(f'  {nm}: {dict(cnt)}')
print('행높이:', dict(Counter(ws.row_dimensions[r].height for r in range(1,ws.max_row+1))))
print('헤더병합:', [h for h in ('B1:R1','S1:W1','Y1:AA1') if h in {str(m) for m in ws.merged_cells.ranges}],'총병합', len(ws.merged_cells.ranges))
bad=sum(1 for r in data if ws.cell(r,11).value and str(ws.cell(r,11).value).startswith('http') and (not ws.cell(r,11).hyperlink or ws.cell(r,11).hyperlink.target!=ws.cell(r,11).value))
print('K 하이퍼링크 불일치:', bad)
