"""replace_sanoe_images_xlsx.py 가 '형상 일람(모델)' 상단의 산외 형상일람 이미지 3장(행 137·177·242)까지 바꿔 버린 것을 복원(형상일람_산외_*.png, 폭 1260).""" import hashlib, shutil from pathlib import Path import openpyxl from openpyxl.drawing.image import Image as XLImage from openpyxl.styles import Font NAME = "4개교_공통사항_종합.xlsx" REV = Path(r"D:\★Pier 자료\프로그램\Pier_T\검토파일"); ORIG = Path(r"D:\★Pier 자료\심수석님 검토 파일"); CAP = REV / "수정후_캡처" wb = openpyxl.load_workbook(REV / NAME); sh = wb["형상 일람(모델)"] fix = {137: ("산외 기초", "형상일람_산외_기초.png"), 177: ("산외 코핑", "형상일람_산외_코핑.png"), 242: ("산외 기둥", "형상일람_산외_기둥.png")} n = 0 for i, im in enumerate(sh._images): r = im.anchor._from.row if r in fix: t, f = fix[r] new = XLImage(str(CAP / f)); h = new.height * 1260 / new.width; new.width, new.height = 1260, int(h) new.anchor = im.anchor; sh._images[i] = new sh.cell(row=r, column=1, value=t); n += 1 print("restored", n) 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))