Remove a worksheet in Excel using r package xlsx

陌路散爱 提交于 2021-02-07 09:15:23

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!