ycphs/openxlsx

freezePane only works on document without previously freezed panes

Closed this issue · 2 comments

Describe the bug
freezePane() does not freeze panes when called on a workbook which might have previously had panes freezed. Freezing panes therefore works on documents generated in-memory, but does not work consistently on documents loaded from disk.

When it works:

  • When you're generating a new in-memory workbook
  • When you're loading a workbook that never had any panes freezed

When it does not work:

  • When you're opening a workbook with freezed panes and trying to change/remove freezed panes.
  • When you're trying to freeze panes in a workbook that previously had freezed panes, but those panes were unfreezed in Excel GUI.

To Reproduce

  1. Generate a document with freeze panes:
wb <- createWorkbook("Kenshin")
addWorksheet(wb, "Sheet 1")
freezePane(wb, sheet=1, firstActiveRow = 2, firstActiveCol = 2)
saveWorkbook(wb, "freezedPanes.xlsx", overwrite = TRUE)
  1. Open the document in Excel and confirm the first row and first column is freezed
  2. (optionally) Unfreeze the panes in Excel GUI and save the document
  3. Try to change the freezed panes:
wb <- loadWorkbook("freezedPanes.xlsx")
freezePane(wb, sheet=1, firstActiveRow = 3, firstActiveCol = 3)
saveWorkbook(wb, "freezedPanes.xlsx", overwrite = TRUE)

Expected behavior
Upon opening the file in Excel, I expect the first two rows and first two columns be freezed.

Actual behaviour
Freezed panels won't change.
If you have removed the freezed panes in Excel GUI, upon running the second snippet you still won't have any panes freezed. If you have not removed freezed panes in Excel GUI, only the first row and first column will be freezed (that is, from running the first script)

Additional context
The amount of previously or newly freezed panes and columns does not matter, at least from what I could see from my experimentation. Only the previously-freezed-panes state matters. I had previously suspected that the Excel program has changed the way of freezing the panes, which is currently unreadable to openxlsx, but that does not seem to be the case. Even if you skip step number 3, the bug is still there.

Software version

  • R version 4.2.1 (2022-06-23 ucrt)
  • openxlsx version 4.2.5.1

This issue is stale because it has been open 365 days with no activity. Remove stale label or comment or this will be closed in 7 days.

This issue was closed because it has been stalled for 7 days with no activity.