title: Python - Automatically adjust width of an excel file's columns
body: <p>Newbie - I have a Python script that adjusts the width of different columns of an excel file, according to the values specified:</p>
  
  <pre><code>import openpyxl
  from string import ascii_uppercase
  
  newFile = "D:\Excel Files\abc.xlsx"
  
  wb = openpyxl.load_workbook(filename = newFile)        
  worksheet = wb.active
  
  for column in ascii_uppercase:
      if (column=='A'):
          worksheet.column_dimensions[column].width = 30
      elif (column=='B'):
          worksheet.column_dimensions[column].width = 40            
      elif (column=='G'):
          worksheet.column_dimensions[column].width = 45            
      else:
          worksheet.column_dimensions[column].width = 15
  
  wb.save(newFile)
  </code></pre>
  
  <p>Is there any way through which we can adjust the width of every column to its most optimum value, without explicitly specifying it for different columns (means, without using this "<strong>if-elif-elif-......-elif-else</strong>" structure)? 
  Thanks!</p>