"""'형상 일람(모델)' 시트의 산외 대조 이미지 3장을 원본 DXF 렌더 기준 새 이미지로 교체(같은 위치·폭). 하루 1백업.""" import hashlib, shutil from pathlib import Path import openpyxl from openpyxl.drawing.image import Image as XLImage from xlsx_backup_once import backup_once, NAME ROOT = Path(r"D:\★Pier 자료\프로그램\Pier_T"); REV = ROOT / "검토파일"; ORIG = Path(r"D:\★Pier 자료\심수석님 검토 파일"); CAP = REV / "수정후_캡처" print("backup:", backup_once()) wb = openpyxl.load_workbook(REV / NAME); sh = wb["형상 일람(모델)"] imgs = sorted(range(len(sh._images)), key=lambda i: sh._images[i].anchor._from.row) labels = {r: str(sh.cell(row=r + 1, column=1).value) for r in [sh._images[i].anchor._from.row for i in imgs]} targets = {"산외 코핑": "도면대조_산외_코핑.png", "산외 기초": "도면대조_산외_기초.png", "산외 기둥": "도면대조_산외_기둥.png"} done = 0 for i in imgs: row = sh._images[i].anchor._from.row # 0-based, 제목 셀은 row(1-based)=row title = str(sh.cell(row=row, column=1).value or "") for key, f in targets.items(): if title.startswith(key): old = sh._images[i]; w = old.width new = XLImage(str(CAP / f)); new.width, new.height = w, int(w * new.height / new.width) if False else int(w * XLImage(str(CAP / f)).height / XLImage(str(CAP / f)).width) new.anchor = old.anchor; sh._images[i] = new; sh.cell(row=row, column=1, value=title.split(" —")[0] + " — 형식 그림(원본 DXF 렌더) ↔ 모델 대조"); done += 1 print("replaced", done) wb.save(REV / NAME); shutil.copy2(REV / NAME, ORIG / NAME) sha = lambda p: hashlib.sha256(Path(p).read_bytes()).hexdigest() print("sha equal:", sha(REV / NAME) == sha(ORIG / NAME), sha(REV / NAME)[:16], len(sh._images))