使用R包xlsx在Excel中删除工作表 [英] Remove a worksheet in Excel using r package xlsx

查看:42
本文介绍了使用R包xlsx在Excel中删除工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所述,我想使用带有软件包xlsx的r删除excel中的第二个工作表.但是,运行代码后,什么都没有发生.以下是我用来删除工作表的示例代码:

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)

这篇关于使用R包xlsx在Excel中删除工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆