问题
As the title stated, I would like to delete the second worksheet in excel using r with package xlsx. However, after running the code, nothing happened. Following is a sample code I used to delete the sheet:
path = "C://ECOS//Code//Test//data.xlsx"
sheets = getSheets(loadWorkbook(path))
removeSheet(loadWorkbook(path), sheetName = names(sheets[2]))
Really appreciate helps. Thank you!
回答1:
You need to save the workbook in the same file (or different if you prefer).
wb = loadWorkbook(path)
removeSheet(wb, sheetName = names(sheets[2]))
saveWorkbook(wb, path)
来源:https://stackoverflow.com/questions/34230675/remove-a-worksheet-in-excel-using-r-package-xlsx