【问题标题】:Google Sheet Furcation ( Not Working on Google Form Response Sheet )谷歌表分叉(不适用于谷歌表单响应表)
【发布时间】:2021-05-19 03:48:32
【问题描述】:

这个功能很好用。当前工作表不是 Google 表单响应表时。我正在使用(每分钟)触发器

Image of: Sand data (mainData) sheet to (shareData1) sheet

  • 我正在寻找一个,当用户提交状态为 (Paid) 的 Google 表单时,数据应显示在第二张表上,即 (shareData1)

这里的问题是,当我使用 Google Forms 响应表时,此功能将不再起作用。它显示一个错误。 Error Image

在降级的错误图像中,我手动运行此函数,同样的错误显示在 Executions AppScript 面板中。

function doneCopy() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("mainData");
  var values = sheet.getRange(1, 3, sheet.getLastRow(), 1).getValues();

  var moveRows = values.reduce(function(ar, e, i) {
    if (e[0] == "Paid" ) ar.push(i + 1)
    return ar;

  }, []);

  var targetSheet = ss.getSheetByName("shareData1");

  moveRows.forEach(function(e) {
    sheet.getRange(e, 1, 1, sheet.getLastColumn()).moveTo(targetSheet.getRange(targetSheet.getLastRow() + 1, 1));
  });
  moveRows.reverse().forEach(function(e) {sheet.deleteRow(e)});
}

【问题讨论】:

    标签: google-apps-script google-sheets google-sheets-api spreadsheet google-forms


    【解决方案1】:
    function doneCopy() {
      const ss = SpreadsheetApp.getActiveSpreadsheet();
      const sh = ss.getSheetByName("mainData");
      const tsh = ss.getSheetByName("shareData1");
      const vs = sh.getRange(1, 3, sh.getLastRow(), 1).getValues().flat();
      const n = sh.getLastColumn();
      let d = 0;
      vs.forEach((e, i) => {
        if (e == 'Paid') {
          sh.getRange(i + 1, 1, 1, n).copyTo(tsh.getRange(tsh.getLastRow() + 1, 1));
          sh.deleteRow(i + 1 - d++);
        }
      });
    }
    

    我不确定您的其他需求是什么,但我会尽力猜测。

    function doneCopy() {
      const ss = SpreadsheetApp.getActiveSpreadsheet();
      const sh = ss.getSheetByName("mainData");
      const tsh = ss.getSheetByName("shareData1");
      const vs = sh.getRange(1, 3, sh.getLastRow(), 1).getValues().flat();
      const n = sh.getLastColumn();
      const a = ['Paid','Process'];
      let d = 0;
      vs.forEach((e, i) => {
        if (~a.indexOf(e)) {
          sh.getRange(i + 1, 1, 1, n).copyTo(tsh.getRange(tsh.getLastRow() + 1, 1));
          sh.deleteRow(i + 1 - d++);
        }
      });
    }
    

    【讨论】:

    • 感谢您的支持,实际上我正在移动两个值,第一个是 Paid,第二个是 Process。 ( e == 'Paid' || e == 'Process' ) 或 else if ( e == 'Process' ) 两次它只会处理第一个值并删除第二个值。在运行函数之前,填充两个条目。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多