将对话框的响应复制到单元格

时间:2019-03-01 01:33:45

标签: google-apps-script copy prompt

因此,我是Google脚本的新手,不确定自己到底在做什么错。我正在尝试将结果从对话框复制到Google表格中的单元格。但是,我正在尝试的当前方法不起作用,并且收到响应,提示“无法在对象中找到要复制到的函数(响应)”

function Cancel() {
  var ui = SpreadsheetApp.getUi();

  var result = ui.prompt(
      'What day did you cancel?',
      'Please enter the date as mm/dd/yyy',
      ui.ButtonSet.OK_CANCEL);

  // Process the user's response.
  var button = result.getSelectedButton();
  var text = result.getResponseText();
  var sheet = SpreadsheetApp.getActiveSheet(),
    row = sheet.getLastRow();

  if (button == ui.Button.OK) {
    // User clicked "OK".
    sheet.insertRowAfter(row);
      text.copyTo(sheet.getRange(row + 1, 1));
    ui.alert('The Date has Been Recorded');
  } else if (button == ui.Button.CANCEL) {
    // User clicked "Cancel".
    ui.alert('I did not get your name.');
  } else if (button == ui.Button.CLOSE) {
    // User clicked X in the title bar.
    ui.alert('You closed the dialog.');
  }
}

任何人都可以看看我的代码,并就如何将响应复制到单元格提出建议。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

怎么样:

而不是:text.copyTo(sheet.getRange(row + 1, 1));

尝试:sheet.getRange(row + 1, 1).setValue(text);