在电子表格Google Apps脚本中增加单元格值

时间:2014-12-08 13:18:52

标签: javascript google-apps-script

我想增加A1单元格中的值。

function increment(){
   var ss = SpreadsheetApp.getActiveSpreadsheet();
   var sheet = ss.getSheets()[0];

   var cell = sheet.getRange("A1");
   cellValue = cell.getValue("A1");
   cell.SetValue(cellValue + 1);
}

我该怎么做?

1 个答案:

答案 0 :(得分:7)

您正在使用参数调用getValue()。此函数不带任何参数,如文档中所示:

https://developers.google.com/apps-script/reference/spreadsheet/range#getValue()

  function increment(){
   var ss = SpreadsheetApp.getActiveSpreadsheet();
   var sheet = ss.getSheets()[0];

   var range = sheet.getRange("A1");
   //Returns the value of the top-left cell in the sheet
   var value = range.getValue();
   range.setValue(value + 1);
}