【问题标题】:Overwrite worksheet using googlesheets in R在 R 中使用 googlesheets 覆盖工作表
【发布时间】:2017-12-16 12:03:39
【问题描述】:

我有 2 个问题。

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

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

我在the documentation. 中找不到任何内容

【问题讨论】:

    标签: r overwrite google-sheets-api worksheet r-googlesheets


    【解决方案1】:

    您可以使用gs_edit_cells() 直接覆盖工作表中的数据,使用trim = TRUE 选项擦除工作表中的任何额外内容。正如文档指出的那样,使用此函数以及因此依赖它的任何函数(包括 input 不为 NULL 时的 gs_ws_new())将是 extremely slow

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

    【讨论】:

      【解决方案2】:

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

      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
            )
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-07-28
        • 2019-07-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多