我有2个问题。
-
如何使用 R 中的 googlesheets 包覆盖现有电子表格中的工作表?
-
如何使用 R 中的谷歌工作表包在现有电子表格中创建新工作表?
我在文档中找不到任何内容。
您可以使用gs_edit_cells()
直接覆盖工作表中的数据,也可以使用trim = TRUE
选项擦除工作表中多余的内容。正如文档所指出的,使用此函数以及因此依赖它的任何函数(包括gs_ws_new()
如果input
不是 NULL(将非常慢。
唯一可用的其他选项是构建一个包含所有感兴趣的工作表(例如.xlsx(的完整文件并使用gs_upload()
,这将覆盖您的整个文件。
要在现有电子表格中添加新工作表:
require(googlesheets)
#first get the existing spreadsheet
existing_spreadsheet <- gs_title("title")
#Then add the new worksheet to the existing sheet
gs_ws_new(existing_spreadsheet
, ws_title = "worksheet title" #make sure it doesn't exist already
, input = your_input #data.frame or data.table
, trim = TRUE #optional if you want your worksheet trimed
)
我自己无法找到覆盖现有电子表格中的工作表的直接方法。所以我不得不删除现有的工作表,然后再次将其添加为新工作表。
#first delete the existing worksheet
existing_spreadsheet <- gs_ws_delete(existing_spreadsheet, "work sheet title you want updated")
# Then add the newworksheet with new data
gs_ws_new(existing_spreadsheet
, ws_title = "worksheet title"
, input = your_new_data #data.frame or data.table
, trim = TRUE #optional if you want your worksheet trimed
)