1

我觉得我的答案在这里:Apply If/Then on a Range (google-apps-script) 但我收到 getA1Notation() 错误。我在另一个文档上构建了一个脚本,以通过触发器在我的新文档中自动填充一行。现在,在新文档中,我想 onEdit 确定列 C 是否有 2 个值(用逗号分隔),然后复制行并拆分列 C。这是我的代码:

function onEdit(){
  var targetSS = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Tech Newsletter - Current');
  var targetLastRow = targetSS.getLastRow();
  var targetNewRow = targetLastRow+1;

  var multipleMfg = targetSS.getRange("C"+targetLastRow).getValue();  
  if (multipleMfg.indexOf(",") !== -1) {
    var splitCell = '=SPLIT('+ multipleMfg.getA1Notation() + ',",")';
    targetNewRow.getRange("C").setFormula(splitCell);
  }
}

我意识到我需要添加更多内容来填充行的其余部分,因为我最担心拆分以及为什么我收到错误“无法在对象 Southern, Northern 中找到 getA1Notation 的函数”。我是一名自学成才的脚本编写者,我不理解developers.google.com/apps-script/referece 上提供的定义

4

1 回答 1

2

You are making confusion between different data types.

targetNewRow is an integer : it has no getRange method

multipleMfg is a string, it has no getA1Notation method

I changed a few things to make it work, see below:

function onEdit(){
  var targetSS = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('filters');
  var targetLastRow = targetSS.getLastRow();
  var targetNewRow = targetLastRow+1;
  var multipleMfg = targetSS.getRange("C"+targetLastRow).getValue();  
  if (multipleMfg.indexOf(",") !== -1) {
    var splitCell = multipleMfg.split(',');
    var result = [];
    for(var n in splitCell){
      result.push([splitCell[n]]);
    }
    targetSS.getRange(targetNewRow,3,result.length,result[0].length).setValues(result);
  }
}

enter image description here

于 2013-10-11T16:54:38.350 回答