_autofit_column_width

pyhelpers.store._autofit_column_width(writer, writer_kwargs, **kwargs)[source]

Adjusts the column widths in an Excel spreadsheet based on the content length.

This function is specifically designed for openpyxl engine when working with Pandas ExcelWriter. It iterates through each column of the specified sheet and calculates the maximum length of the content. It then adjusts the column width to accommodate the longest content plus some padding.

Parameters:
  • writer (pandas.ExcelWriter) – ExcelWriter object used to write data into Excel file.

  • writer_kwargs (dict) – Keyword arguments passed to the ExcelWriter, including the engine.

  • kwargs – [Optional] Additional parameters.

Note

  • This function assumes that openpyxl engine is used (i.e. writer_kwargs['engine'] == 'openpyxl').

  • It modifies the column dimensions directly in the pandas.ExcelWriter object.

See also