# -*- coding: utf-8 -*-
import openpyxl, io
wb=openpyxl.load_workbook("한국임업진흥원.xlsx"); ws=wb.active
out=io.open("_spot_out.txt","w",encoding="utf-8")
def gl(c): return openpyxl.utils.get_column_letter(c)
# find rows for groups by scanning
def dump(r1,r2,tag):
    out.write("\n### %s\n"%tag)
    for r in range(r1,r2+1):
        vv=[]
        for c in range(2,18):
            v=ws.cell(r,c).value
            if v is not None and str(v).strip()!="": vv.append("%s=%s"%(gl(c),v))
        out.write("%d %s\n"%(r," | ".join(vv)))
# locate 임산물정보 sibling block and 상임이사
mr={str(m) for m in ws.merged_cells.ranges}
# print merges in F/G to check 상임이사 not merged
out.write("merges touching 상임이사 area:\n")
for m in ws.merged_cells.ranges:
    out.write("  "+str(m)+"\n")
out.close()
# now just dump key ranges
out=io.open("_spot_out.txt","a",encoding="utf-8")
for r in range(3,ws.max_row+1):
    if ws.cell(r,6).value in("임산물 정보",) or ws.cell(r,7).value=="산나물":
        dump(max(3,r-1),r+5,"임산물정보 sibling @r%d"%r); break
for r in range(3,ws.max_row+1):
    if ws.cell(r,7).value=="이사장(원장)":
        dump(r-1,r+3,"상임이사 dup-label @r%d"%r); break
for r in range(3,ws.max_row+1):
    if ws.cell(r,7).value=="윤리서약":
        dump(r-1,r+3,"윤리 group @r%d"%r); break
out.close(); print("done")
