简体   繁体   中英

Remove a worksheet in Excel using r package xlsx

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!

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM