def get_col_widths(dataframe):
    idx_max = max([len(str(s)) for s in dataframe.index.values] + [len(str(
        dataframe.index.name))])
return [idx_max] + [max([len(str(s)) for s in dataframe[col].values] + [len
    (col)]) for col in dataframe.columns]
for i, width in enumerate(get_col_widths(metrics)):
    worksheet.set_column(i, i, width)
Имитация столбца автоподбора в xlsxwriter