awalker89/openxlsx

loadWorkbook has corrupted workbook if sort exists

Opened this issue · 1 comments

Expected Behavior

wb <- loadWorkbook("testCorrupting.xlsx") #that has a sort as part of a filter
saveWorkbook(wb,"testCorrupted.xlsx", overwrite=TRUE)

open testCorrupted.xlsx - should not come up as corrupt.

Actual Behavior

open testCorrupted.xlsx - Excel says it is corrupted.

clearing the autoFilter field of the worksheet object before saving resolves it, but drops the filter and sort:

wb <- loadWorkbook("testCorrupting.xlsx") #that has a sort as part of a filter
wb[["worksheets"]][1][[1]][["autoFilter"]]
[1] "<autoFilter ref="A1:C1"><sortState ref="A2:C5"><sortCondition ref="B1"/>"

wb[["worksheets"]][1][[1]][["autoFilter"]] <- character(0)

also the following works as it is only the sort that causes an issue:

wb[["worksheets"]][1][[1]][["autoFilter"]] <- "<autoFilter ref="A1:C1"/>
saveWorkbook(wb,"testCorrupted.xlsx", overwrite=TRUE)

Steps to Reproduce the Problem

(please attach an example xlsx file if possible)
testCorrupting.xlsx

  1. Have a spreadsheet with a filter added and a column sorted as in testCorrupting.xlsx

  2. do the following in R

wb <- loadWorkbook("testCorrupting.xlsx")
saveWorkbook(wb,"testCorrupted.xlsx", overwrite=TRUE)

  1. Attempt to open testCorrupted.xlsx

sessionInfo()

  • Version of openxlsx: openxlsx_4.2.3
  • Version of R: 3.6.1 (2019-07-05)

I had exactly the same issue.
Can you report this bug to the "active" openxlsx repository : https://github.com/ycphs/openxlsx/issues

It looks like awalker89/openxlsx is the old repository and is not active anymore