You can use the pywin32 library:
from win32com.client import Dispatch
excel = Dispatch('Excel.Application')
wb = excel.Workbooks.Open("D:\\output.xlsx")
excel.Worksheets(2).Activate()
excel.ActiveSheet.Columns.AutoFit()
wb.SaveAs("D:\\output_fit.xlsx")
wb.Close()
source
share