Google apps script 谷歌表单设置值

Google apps script 谷歌表单设置值,google-apps-script,google-sheets,Google Apps Script,Google Sheets,尝试编写一个脚本,用弹出框提示输入值,然后将该值添加到已输入的金额中 function addDKP(){ // Prompt for the value var amount = SpreadsheetApp.getUi().prompt("Please Enter the DKP Amount").getResponseText(); var sheetName = "Sheet1" ; var selection = SpreadsheetApp.getActiveSp

尝试编写一个脚本,用弹出框提示输入值,然后将该值添加到已输入的金额中

function addDKP(){
  // Prompt for the value
  var amount =  SpreadsheetApp.getUi().prompt("Please Enter the DKP Amount").getResponseText();

  var sheetName = "Sheet1" ;
  var selection = SpreadsheetApp.getActiveSpreadsheet().getSelection();

  // Returns the current highlighted cell in the one of the active ranges.
  var currentCell = selection.getCurrentCell();
  var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
  var range = selection.getActiveRange();
  var value = range.getValue();

  range.setValue(amount + value );
}
该脚本正在工作,但只是将输入的金额添加到已输入值的末尾

例如:

Current Cell value = 45
Run script and enter 2 as a value
End of script cell value = 452 
预期单元格值应为
47


如果您能就发生这种情况的原因提出任何建议,我们将不胜感激。

这些是实际的数字吗?您可以使用
range.setValue(Number(amount)+Number(value))完美,谢谢!传奇