awalker89 / openxlsx

R package for .xlsx file reading and writing.
Other
363 stars 79 forks source link

loadWorkbook has corrupted workbook if sort exists #524

Open bsleik opened 3 years ago

bsleik commented 3 years ago

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()

JMPivette commented 3 years ago

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