code: def write_sheet(writer, name, df, index=False):
      
      if index:
          df = df.reset_index()
      df.to_excel(writer, name, index=False)
      worksheet = writer.sheets[name]
      for i, col in enumerate(df.columns):
          if df.dtypes[col].name.startswith(('float', 'int')):
              width = len(str(col)) + 2
          else:
              width = max([df[col].map(lambda x: len(str(x or 'None'))).max(),
                           len(col)]) + 2
          xls_col = '{c}:{c}'.format(c=NUMERIC_TO_STR[i])
          worksheet.set_column(xls_col, width)
docs: Write a pandas DataFrame to an ExcelWriter,
      auto-formatting column width depending on maxwidth of data and colum header
  
      Parameters
      ----------
      writer: pandas.ExcelWriter
          an instance of a pandas ExcelWriter
      name: string
          name of the sheet to be written
      df: pandas.DataFrame
          a pandas DataFrame to be written to the sheet
      index: boolean, default False
          flag whether index should be written to the sheet