【问题标题】:Automatically Paste Data from Latest CSV File in Google Drive Folder to Google Sheet自动将 Google Drive 文件夹中最新 CSV 文件中的数据粘贴到 Google Sheet
【发布时间】:2021-04-23 18:30:38
【问题描述】:

我有一个非常具体的要求,即自动将每日数据转储到我需要帮助的 Google 表格中。我对编码很陌生,所以我不确定从哪里开始,而且谷歌搜索到目前为止还没有取得成果。我将尽可能详细地描述我的问题,并乐于根据需要提供更多详细信息。

  1. 每天一次,通常是在上午,但不是在确切的特定时间,一个 CSV 文件会上传到名为“Daily Pacing Folder”的 Google Drive 文件夹中
  2. CSV 文件始终包含相同的标题列标题,以及根据日期而定的可变行数
  3. CSV 文件每天都有不同的文件名
  4. CSV 文件的内容被粘贴到名为“销售报告”的 Google 表格中,表格名称为“原始数据 *”。 “销售报告”Google 表格包含几个不同的表格,这些表格已经具备各种功能
  5. 我无法每天覆盖“原始数据 *”表。我想获取最新的 CSV 文件的内容,并将文件粘贴到 E:Y 列中

理想情况下,我想要自动化的是检查文件夹“每日起搏文件夹”的脚本,如果它看到该文件夹​​中包含新的 CSV,则获取 CSV 内容并将 E:Y 列粘贴到 Google 表格“销售报告”中,在工作表“原始数据 *”中。

如果有人能在这里帮助我,我将不胜感激。 如果我可以提供更多信息或澄清,请告诉我,并提前感谢您!

【问题讨论】:

    标签: google-apps-script google-sheets


    【解决方案1】:
    function loadCSVintoSpreadsheet() {
      const ss = SpreadsheetApp.getActive();
      const ui = SpreadsheetApp.getUi();
      const resp1 = ui.prompt('Select Sheet Name', 'Enter destination sheet name', ui.ButtonSet.OK_CANCEL);
      if (resp1.getSelectedButton() == ui.Button.OK && resp1.getResponseText().length > 0) {
        const sh = ss.getSheetByName(resp1.getResponseText());
        //sh.clearContents();
        const resp2 = ui.prompt('CSV FileId', 'Enter file id of csv', ui.ButtonSet.OK_CANCEL);
        if (resp2.getSelectedButton() == ui.Button.OK && resp2.getResponseText().length > 0) {
          const file = DriveApp.getFileById(resp2.getResponseText());
          const csv = file.getBlob().getDataAsString();
          let csvA = Utilities.parseCsv(csv)
          sh.getRange(sh.getLastRow()+1, 1, csvA.length, csvA[0].length).setValues(csvA);
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-08
      • 2021-04-02
      • 2021-12-10
      • 1970-01-01
      • 2013-03-01
      • 2018-08-17
      • 1970-01-01
      • 2018-10-22
      相关资源
      最近更新 更多