import os import openpyxl input_file = "storage/app/templates/template_spip.xlsx" output_file = "storage/app/templates/template_spip_clean.xlsx" if not os.path.exists(input_file): print(f"Error: File {input_file} tidak ditemukan!") exit() print("1. Sedang membaca file template Excel (mohon tunggu)...") wb = openpyxl.load_workbook(input_file, data_only=False) print("2. Memproses pembersihan baris & kolom siluman di seluruh sheet...") for sheet_name in wb.sheetnames: ws = wb[sheet_name] max_r = 1 max_c = 1 # Cari sel terbawah & terkanan yang benar-benar ada isinya for row in ws.iter_rows(): for cell in row: if cell.value is not None: if cell.row > max_r: max_r = cell.row if cell.column > max_c: max_c = cell.column # Pangkas baris & kolom kosong berlebih di luar area data if ws.max_row > max_r + 5: ws.delete_rows(max_r + 1, ws.max_row - max_r) if ws.max_column > max_c + 5: ws.delete_cols(max_c + 1, ws.max_column - max_c) print("3. Menyimpan file hasil pembersihan...") wb.save(output_file) ukuran_lama = os.path.getsize(input_file) / 1024 ukuran_baru = os.path.getsize(output_file) / 1024 print("--------------------------------------------------") print(f"SELESAI! File bersih berhasil dibuat.") print(f"Ukuran Asli : {ukuran_lama:.1f} KB") print(f"Ukuran Baru : {ukuran_baru:.1f} KB") print("--------------------------------------------------")