auto_size not working

Issue #425 invalid
Franco Solleza created an issue

When I do:

wb =openpyxl.load_workbook([some empty xlsx workbook])
sheet = wb.get_sheet_by_name('Sheet1')
sheet.cell('A2').value = "FADFLN LSFNLVMSJIOSERJGMOSJGMLSLFJ"
sheet.column_dimensions['A'].auto_size = True
wb.save("[some new workbook]")

Nothing happens to column A

but when I do:

wb =openpyxl.load_workbook([some empty xlsx workbook])
sheet = wb.get_sheet_by_name('Sheet1')
sheet.cell('A2').value = "FADFLN LSFNLVMSJIOSERJGMOSJGMLSLFJ"
sheet.column_dimensions['A'].width = 50
wb.save("[some new workbook]")

The width of column A changes. Am I missing something? Thanks!

Comments (4)

  1. CharlieC

    The bug tracker is not the place to ask questions.

    This is what the specification says:

    Flag indicating if the specified column(s) is set to 'best fit'. 'Best fit' is set to true under these conditions:

    • 􏰀 The column width has never been manually set by the user, AND

    • 􏰀 The column width is not the default width 􏰀

    • 􏰀 'Best fit' means that when numbers are typed into a cell contained in a 'best fit' column, the column width should automatically resize to display the number. [Note: In best fit cases, column width must not be made smaller, only larger. end note]

    Looks self-contradictory to me. Note that when you double-click on a column to automatically resize it Excel sets a specific column and also the alignment for cells contained in it.

  2. Franco Solleza reporter

    Sorry about that - I saw an older bug with auto_size and wasn't sure if it was back. Thanks for responding nonetheless...

  3. CharlieC

    It would have been fine to reopen the bug but the mailing list is a better place to ask questions. They may get more eyes and the discussions are more fruitful. It's important to understand that openpyxl deals with the file format rather than trying to emulate Excel application.

  4. Log in to comment