import sys, io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
import openpyxl
PKG = r'D:\01.프로젝트\DB수집\작업파일\_제출패키지_2026-06-03\프리랜서1\충청남도_부여군.xlsx'
WRK = r'D:\01.프로젝트\DB수집\작업파일\광역_사이트맵\충청남도\7.부여군\충청남도_부여군.xlsx'
wb = openpyxl.load_workbook(PKG); ws = wb.active

def cellinfo(r,c):
    cell=ws.cell(r,c)
    a=cell.alignment; f=cell.font
    return f'wrap={a.wrap_text} font={f.name},{f.size}'

print('=== row 515 (h=15) vs 522 (h=16.5) cell C,G ===')
for r in (515,522):
    print(f' r{r} h={ws.row_dimensions[r].height}: C[{cellinfo(r,3)}] G[{cellinfo(r,7)}] K[{cellinfo(r,11)}]')

# height histogram all rows
from collections import Counter
hc=Counter(ws.row_dimensions[r].height for r in range(1,ws.max_row+1))
print('\nheight histogram:', dict(hc))

# any row with B present but no K and no menu D-J (blank-ish content row)
print('\n=== B present but K empty & D-J empty ===')
for r in range(3, ws.max_row+1):
    if ws.cell(r,2).value in (None,''): continue
    k=ws.cell(r,11).value
    menu=any(ws.cell(r,c).value not in (None,'') for c in range(4,11))
    # account for merged D/E/F inheritance
    if k in (None,'') and not menu:
        print(f'  r{r} B={ws.cell(r,2).value} (no K, no own menu)')

# fully blank rows anywhere 1..max
blank=[r for r in range(1,ws.max_row+1) if all(ws.cell(r,c).value in (None,'') for c in range(1,28))]
print('\n완전빈행(1..max):', blank)

# compare PKG vs WRK cell-by-cell (values)
wb2=openpyxl.load_workbook(WRK); ws2=wb2.active
print(f'\nPKG max_row={ws.max_row} WRK max_row={ws2.max_row}')
diff=0
for r in range(1,max(ws.max_row,ws2.max_row)+1):
    for c in range(1,28):
        if ws.cell(r,c).value!=ws2.cell(r,c).value:
            diff+=1
            if diff<=10: print(f'  val diff r{r}c{c}: PKG={ws.cell(r,c).value!r} WRK={ws2.cell(r,c).value!r}')
print('value diffs PKG vs WRK:', diff)
# height diffs
hd=[r for r in range(1,ws.max_row+1) if ws.row_dimensions[r].height!=ws2.row_dimensions[r].height]
print('height diffs PKG vs WRK rows:', len(hd), hd[:10])
