# -*- coding: utf-8 -*-
import openpyxl, io
def eff_paths(path):
    wb=openpyxl.load_workbook(path); ws=wb.active; mx=ws.max_row
    eff={}
    for r in range(3,mx+1):
        for c in range(4,11): eff[(r,c)]=ws.cell(r,c).value
    for mr in ws.merged_cells.ranges:
        if mr.min_row>=3 and mr.min_col>=4 and mr.max_col<=10:
            v=ws.cell(mr.min_row,mr.min_col).value
            for r in range(mr.min_row,mr.max_row+1):
                for c in range(mr.min_col,mr.max_col+1): eff[(r,c)]=v
    def E(r,c):
        v=eff.get((r,c)); return str(v).strip() if v not in(None,"") else ""
    return mx,{r:tuple(E(r,c) for c in range(4,11)) for r in range(3,mx+1)}
mx1,b=eff_paths("_backup/충청남도_부여군_backup_셀병합전.xlsx")
mx2,a=eff_paths("충청남도_부여군.xlsx")
out=io.open("_chk_buyeo_out.txt","w",encoding="utf-8")
out.write("rows before %d after %d\n"%(mx1,mx2))
diff=0
for r in sorted(a):
    if b.get(r)!=a.get(r):
        diff+=1
        if diff<=40:
            out.write("r%d\n  before: %s\n  after : %s\n"%(r," > ".join(x for x in b.get(r,()) if x)," > ".join(x for x in a[r] if x)))
out.write("\ntotal changed-path rows: %d\n"%diff)
out.close(); print("diff",diff)
