Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 从一个单元格中获取注释并插入到另一个单元格中_Google Apps Script_Google Sheets - Fatal编程技术网

Google apps script 从一个单元格中获取注释并插入到另一个单元格中

Google apps script 从一个单元格中获取注释并插入到另一个单元格中,google-apps-script,google-sheets,Google Apps Script,Google Sheets,我在谷歌的表格里有一系列的单元格,其中一些还附有注释 如果有一个便笺附加到一个单元格,我需要将便笺放在一个单独的单元格中,并将该便笺的位置放在另一个单元格中 我在别处找到了这个脚本: function getNote(cell) { var ss = SpreadsheetApp.getActiveSpreadsheet(); var range = ss.getRange(cell) return range.getNote(); } 但是当我尝试使用它时,我得到了一个错

我在谷歌的表格里有一系列的单元格,其中一些还附有注释

如果有一个便笺附加到一个单元格,我需要将便笺放在一个单独的单元格中,并将该便笺的位置放在另一个单元格中

我在别处找到了这个脚本:

function getNote(cell)
{
   var ss = SpreadsheetApp.getActiveSpreadsheet();
   var range = ss.getRange(cell)
   return range.getNote();
}

但是当我尝试使用它时,我得到了一个错误“Exception:Range not found(第12行)”

但是这个脚本只让我走了一半,因为它只把便条放进了一个单元格。我还需要知道这张纸条是从哪个细胞来的

非常感谢您的帮助。

在上面的脚本中,函数
getNote()
需要参数
cell
如果您只是运行脚本,而没有从另一个函数/环境调用
getNote()
,在该函数/环境中为
cell
分配值,则脚本将因您获得的错误而失败

事实上,这个脚本不能满足您的需要。您可能需要的是筛选所有单元格中有注释的单元格

您需要决定的是要将注释和单元格符号放入哪个单元格中

以下是您需要根据需要进行调整的示例:

function getNotes() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  //if you have only one sheet in the spreadsheet, otherwise use ss.getSheetByName(name);
  var sheet = ss.getActiveSheet();
  var range = sheet.getDataRange();  
  var results = range.getNotes();  
  for (var i = 0; i < results.length; i++) {
    for (var j = 0; j < results[0].length; j++) {
      //if a not empty note was found:
      if(results[i][j]){
        var note = results[i][j];
        var cell = range.getCell(i+1, j+1);
        var notation = cell.getA1Notation();
        //adjust the offset as function of the column / row where you want to output the results
        cell.offset(0, 1).setValue(note);
        cell.offset(0, 2).setValue(notation);
      }
    }
  }
}
函数getNotes(){ var ss=SpreadsheetApp.getActiveSpreadsheet(); //如果电子表格中只有一张工作表,则使用ss.getSheetByName(name); var sheet=ss.getActiveSheet(); var range=sheet.getDataRange(); var results=range.getNotes(); 对于(var i=0;i 重要参考资料: