import sys, io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
import openpyxl
P = r'D:\01.프로젝트\DB수집\작업파일\광역_사이트맵\충청남도\10.아산시\충청남도_아산시.xlsx'
wb = openpyxl.load_workbook(P); ws = wb.active

print('=== existing &pg= in K (whole file) ===')
n=0
for r in range(3, ws.max_row+1):
    k=ws[f'K{r}'].value
    if k and '&pg=' in str(k):
        print(f'r{r}: F={ws[f"F{r}"].value!r} G={ws[f"G{r}"].value!r} K={k}'); n+=1
print('count', n)

print('\n=== merges touching rows 37-47 ===')
for m in sorted(ws.merged_cells.ranges, key=lambda x:(x.min_row,x.min_col)):
    if m.min_row<=47 and m.max_row>=37:
        print(m, '| min_row',m.min_row,'max_row',m.max_row,'col',m.min_col)

print('\n=== row37 cells full ===')
for c in 'ABCDEFGHIJKLMNOPQRS':
    cell=ws[f'{c}37']
    print(c, repr(cell.value), '| hyperlink=', cell.hyperlink.target if cell.hyperlink else None)

print('\n=== F37 in any merge? ===')
for m in ws.merged_cells.ranges:
    if m.min_col==6 and m.min_row<=37<=m.max_row:
        print('F merge:', m)

print('\n=== rows 37,38 K hyperlinks ===')
for r in (37,38,39,46,47):
    k=ws[f'K{r}']
    print(f'r{r} K={k.value!r} hl={k.hyperlink.target if k.hyperlink else None}')
print('total merges:', len(ws.merged_cells.ranges))
