Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deleting columns does not adjust column dimensions #65

Open
Phrogz opened this issue Nov 23, 2024 · 1 comment
Open

Deleting columns does not adjust column dimensions #65

Phrogz opened this issue Nov 23, 2024 · 1 comment

Comments

@Phrogz
Copy link

Phrogz commented Nov 23, 2024

Steps to reproduce:

  1. Create a workbook in Excel with varying column widths
    image
  2. Open in openpyxl
  3. Use worksheet.delete_cols() to remove a column (e.g. column C in above)
  4. Save the workbook and open in Excel

Expected: deleting column(s) adjusts the column_dimensions to match, as in Excel:
image

Actual: the original column dimensions are retained while the content is shifted:
image

@Phrogz
Copy link
Author

Phrogz commented Nov 23, 2024

Workaround: before you modify columns, set up a list of widths. Every time you delete column(s) or insert them, manually mutate this list. At the end, re-set all the widths.

Workaround: make wrapper functions for delete_cols and insert_cols, which shift all the widths in the column_dimensions map manually every time. (ick)

Feels like this bug came about because the implementation uses a mapping instead of a list, so it's "hard"/expensive to update on each column mutation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant