import openpyxl
wb=openpyxl.load_workbook("한국임업진흥원.xlsx")
ws=wb.active
nr=ws.max_row
# B 연속
bs=[ws.cell(r,2).value for r in range(3,nr+1)]
bad_b=[(i,b) for i,b in enumerate(bs) if b!=i+1]
print("B 연속:", "PASS(1~%d)"%len(bs) if not bad_b else f"FAIL {bad_b[:5]}")
# merged map for DEF holes
filled={}
for m in ws.merged_cells.ranges:
    top=ws.cell(m.min_row,m.min_col).value
    for r in range(m.min_row,m.max_row+1):
        for c in range(m.min_col,m.max_col+1): filled[(r,c)]=top
def eff(r,c): return filled.get((r,c),ws.cell(r,c).value)
# DEF구멍: 어떤 행에서 D비고 E채워지면 안됨(상위 비면 하위도 비어야) — leaf 연속성 체크
holes=0
for r in range(3,nr+1):
    e=[eff(r,c) for c in range(4,11)]  # D..J
    seen_empty=False
    for v in e:
        filledv = v is not None and str(v).strip()!=""
        if seen_empty and filledv: holes+=1; break
        if not filledv: seen_empty=True
print("DEF~J 계층구멍(상위빈데하위참):", "PASS(0)" if holes==0 else f"FAIL {holes}")
# K 하이퍼링크 일치
kbad=0
for r in range(3,nr+1):
    k=ws.cell(r,11)
    if k.value and str(k.value).startswith("http"):
        if k.hyperlink and str(k.hyperlink.target).strip()!=str(k.value).strip(): kbad+=1
print("K 하이퍼링크 불일치:", "PASS(0)" if kbad==0 else f"FAIL {kbad}")
# tech_02 자식 카운트
t02=sum(1 for r in range(3,nr+1) if "tech_02.do?" in str(ws.cell(r,11).value or ""))
print(f"tech_02 mc_cd 자식행: {t02} (기대 15)")
print("총 데이터행:", nr-2)
