5

我有 2 个问题。

  1. 如何使用 R 中的 googlesheets 包覆盖现有电子表格中的工作表?

  2. 如何使用 R 中的 googlesheets 包在现有电子表格中创建新工作表?

我在文档中找不到任何内容。

4

2 回答 2

3

您可以使用删除工作表中任何额外内容gs_edit_cells()的选项直接覆盖工作表中的数据。trim = TRUE正如文档所指出的,使用这个函数,因此,任何依赖它的函数(包括gs_ws_new()if inputis not NULL)都会非常慢

唯一可用的其他选项是构建一个包含所有感兴趣的工作表的完整文件(例如.xlsx)并使用gs_upload(),这将覆盖您的整个文件。

于 2018-08-19T03:15:29.637 回答
1

要在现有电子表格中添加新工作表:

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
      )
于 2018-03-29T05:50:22.677 回答