openxlsx
openxlsx copied to clipboard
Deleting the only sheet from a Workbook and creating it again, corrupts the Excel file
Note, the below does not return an error when the WB is created through createWorkbook, but in the follwoing way:
- 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. - Save the Excel file, in my case "test.xlsx".
- 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.