# -*- coding: utf-8 -*-
import openpyxl, io, os, glob, zipfile, hashlib
SRC="제출_프리랜서2_2026-06-21"
files=sorted([f for f in glob.glob(os.path.join(SRC,"*.xlsx")) if not os.path.basename(f).startswith("~$")])
# 행수 집계 (데이터행 = 3~max, 빈행 제외 대략 max_row-2)
rows=[]
for f in files:
    wb=openpyxl.load_workbook(f); ws=wb.active
    last=2
    for r in range(3,ws.max_row+1):
        if any(ws.cell(r,c).value not in (None,"") for c in range(2,12)): last=r
    rows.append((os.path.splitext(os.path.basename(f))[0], last-2))
    wb.close()
total=sum(n for _,n in rows)
out=io.open("_zip_count_out.txt","w",encoding="utf-8")
out.write("기관수 %d  총 데이터행 %d\n"%(len(rows),total))
for i,(nm,n) in enumerate(rows,1): out.write("%2d. %s : %d행\n"%(i,nm,n))
# zip (17 xlsx만)
zpath="제출_프리랜서2_2026-06-21.zip"
with zipfile.ZipFile(zpath,"w",zipfile.ZIP_DEFLATED) as z:
    for f in files:
        z.write(f, arcname=os.path.basename(f))
out.write("\nZIP: %s  (%d개 파일, %d bytes)\n"%(zpath,len(files),os.path.getsize(zpath)))
# zip 내용 검증
with zipfile.ZipFile(zpath) as z:
    names=z.namelist()
out.write("ZIP 내부: %d개\n"%len(names))
for n in names: out.write("  - %s\n"%n)
out.close()
print("zip done, files",len(files),"total rows",total)
