카테고리 없음

암호화엑셀을 CSV로 변경

유키공 2026. 4. 29. 11:57

import win32com.client as win32
import os

excel = win32.Dispatch("Excel.Application")
excel.Visible = False
excel.DisplayAlerts = False

folder = r"C:\excel_folder"

try:
    for file in os.listdir(folder):
        if file.endswith(".xlsx"):
            xlsx = os.path.join(folder, file)
            wb = excel.Workbooks.Open(xlsx)

            for sheet in wb.Worksheets:
                csv = os.path.join(
                    folder,
                    f"{file.replace('.xlsx','')}_{sheet.Name}.csv"
                )
                sheet.SaveAs(csv, FileFormat=62)

            wb.Close(False)

finally:
    excel.Quit()   # ⭐ 에러 나도 엑셀 강제 종료