Using Python To Autofit All Columns of an Excel Sheet
excel, python
Solution
You can use pywin32 library:
from win32com.client import Dispatch
excel = Dispatch('Excel.Application')
wb = excel.Workbooks.Open("D:\\output.xlsx")
#Activate second sheet
excel.Worksheets(2).Activate()
#Autofit column in active sheet
excel.ActiveSheet.Columns.AutoFit()
#Save changes in a new file
wb.SaveAs("D:\\output_fit.xlsx")
#Or simply save changes in a current file
#wb.Save()
wb.Close()
Problem
Does anyone know of any Python --> Excel libraries that contains a method to autofit all columns within a sheet given a Excel filename?