DB_JOB/작업파일/_스크립트/_fix_cheonan.py
hehihoho3 df16c98366 백업: DB수집 전체 스냅샷 (공공기관2 정리 전)
공공기관2 작업 중. _temp 몽타주(재생성가능)는 제외.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-18 18:15:40 +09:00

45 lines
1.9 KiB
Python

import sys, io, os, shutil, datetime
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
import openpyxl
from openpyxl.styles import Alignment
P = r'D:\01.프로젝트\DB수집\작업파일\광역_사이트맵\충청남도\12.천안시\충청남도_천안시.xlsx'
BK = P.replace('.xlsx','_backup_검수전.xlsx')
if not os.path.exists(BK): shutil.copy2(P,BK); print('backup ->', os.path.basename(BK))
wb=openpyxl.load_workbook(P); ws=wb.active
content=[r for r in range(3,ws.max_row+1) if ws.cell(r,2).value not in (None,'')
or ws.cell(r,11).value not in (None,'') or any(ws.cell(r,c).value not in (None,'') for c in range(4,11))]
# (1) B순번 1..N
for i,r in enumerate(content,1): ws.cell(r,2).value=i
# (2) C 사이트명 빈칸 채움
cfill=0
for r in content:
if ws.cell(r,3).value in (None,''): ws.cell(r,3).value='충청남도 천안시'; cfill+=1
# (3) 행높이 15
fh=0
for r in range(1,ws.max_row+1):
if ws.row_dimensions[r].height not in (15.0,None): ws.row_dimensions[r].height=15.0; fh+=1
# (4) 정렬 통일
nonanchor=set()
for m in ws.merged_cells.ranges:
for rr in range(m.min_row,m.max_row+1):
for cc in range(m.min_col,m.max_col+1):
if not (rr==m.min_row and cc==m.min_col): nonanchor.add((rr,cc))
CEN=Alignment(horizontal='center',vertical='center',wrap_text=True)
LEFT=Alignment(horizontal='left',vertical='center',wrap_text=False)
ac=0
for r in content:
for c in (4,5,6,7):
if (r,c) in nonanchor: continue
ws.cell(r,c).alignment=CEN; ac+=1
if (r,11) not in nonanchor: ws.cell(r,11).alignment=LEFT
# (5) Y/Z/AA (충남=프1, 날짜=내일 2026-06-05)
d=datetime.datetime(2026,6,5); yc=0
for r in content:
ws.cell(r,25).value='Y'; ws.cell(r,26).value=d; ws.cell(r,27).value='프리랜서1'; yc+=1
wb.save(P)
print(f'B순번 {len(content)} | C채움 {cfill} | 높이 {fh} | 정렬 {ac}+K | Y/Z/AA {yc}행(프1·06-05), saved')