I'm trying to auto adjust the column width for multi-sheet excel file and I've stumbled upon this result:
Is there a way to auto-adjust Excel column widths with pandas.ExcelWriter?
It works nicely for a single sheet excel file, but everytime I use writer.save()
it writes over the multi-sheet excel file, making it a single sheet.
My Code:
excel_path = os.path.join(temp_dir, file_name)
for i, (df, sheet_name) in enumerate(zip(dataframe_list, sheet_names)):
if i == 0:
df.to_excel(excel_path, sheet_name=sheet_name)
else:
with pd.ExcelWriter(excel_path, mode='a', engine='openpyxl') as writer:
df.to_excel(writer, sheet_name=sheet_name)
Is there a way to fix this issue?