# -*- coding: utf-8 -*-
import openpyxl, io
def dump(path,tag,r1,r2):
    wb=openpyxl.load_workbook(path); ws=wb.active
    mtop={}
    for mr in ws.merged_cells.ranges:
        for r in range(mr.min_row,mr.max_row+1):
            for c in range(mr.min_col,mr.max_col+1):
                mtop[(r,c)]="M%d:%d"%(mr.min_row,mr.max_row)
    o.write("\n===== %s rows %d-%d =====\n"%(tag,r1,r2))
    for r in range(r1,r2+1):
        cells=[]
        for c in range(4,9):
            v=ws.cell(r,c).value; vv=str(v).strip() if v not in(None,"") else "·"
            mk=mtop.get((r,c),"")
            cells.append("%s=%s%s"%({4:'D',5:'E',6:'F',7:'G',8:'H'}[c],vv,('['+mk+']') if mk else ''))
        o.write("r%d B%s  %s\n"%(r,ws.cell(r,2).value," | ".join(cells)))
o=io.open("_raw_out.txt","w",encoding="utf-8")
dump("_backup/충청남도_부여군_backup_셀병합전.xlsx","BACKUP(원본)",135,160)
dump("충청남도_부여군.xlsx","AFTER(적용후)",135,160)
o.close(); print("done")
