엑셀 너비 자동정렬

try:
    import win32com.client as win32
    excel = win32.Dispatch('Excel.Application')
    load_wb = excel.Workbooks.Open(os.path.abspath(savefilename))
    excel.Visible = False
    for sh in load_wb.Sheets:
        ws = load_wb.Worksheets(sh.Name)
        ws.Columns.AutoFit() # 열너비
        # ws.Rows.AutoFit() # 행높이

    load_wb.Save()
    excel.Application.Quit()
except: #엑셀이 설치되지 않은 환경은 에러남
    pass

Leave a Comment