openxlsx icon indicating copy to clipboard operation
openxlsx copied to clipboard

Deleting the only sheet from a Workbook and creating it again, corrupts the Excel file

Open deschen1 opened this issue 3 years ago • 0 comments

Note, the below does not return an error when the WB is created through createWorkbook, but in the follwoing way:

  1. Open Excel and add some data to it manually. In my example I copied over the mtcars content to the file manually. I named the sheet invalid.
  2. Save the Excel file, in my case "test.xlsx".
  3. Then run the following code in R:
x <- loadWorkbook("test.xlsx")
removeWorksheet(x, "invalid")
addWorksheet(x, "invalid")
writeData(x, "invalid", x = mtcars)
saveWorkbook(x, "test.xlsx", overwrite = TRUE)

When trying to open the Excel file on Windows it returns the probably well-known warning that it tries to restore the content, but then the error that it couldn't restore anything.

deschen1 avatar Mar 14 '22 16:03 deschen1