[英]Adding a value to a cell in javascript
I have created a function that will increase a cell value by 1. The goal is to make the value of AM39 increase by 1, but not go past 2. I have fixed all syntax errors, however I've tried running the script but the script hasn't done anything. 我创建了一个将单元格值增加1的函数。目标是使AM39的值增加1,但不超过2。我已修复了所有语法错误,但是我尝试运行脚本,但脚本什么也没做。
What is wrong is this function? 此功能有什么问题?
function incrementCellValuesByOne() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var cell = sheet.getRange("AM39");
var cell, cellValue;
if (cellValue == cell.getValue()) {
cell.setValue(cellValue + 1);
if (cellValue >= 2) {
cellValue = 2;
}
}
}
edit: 编辑:
range.setValue(value + 1);
if (cellValue >= 2) {
cellValue = 2;
}
You have some wrong in define and ordering of statements! 您在语句的定义和排序中有一些错误! Try this:
尝试这个:
function incrementCellValuesByOne() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var cell, cellValue;
cellValue = "Something you should make here!";
cell = sheet.getRange("AM39");
if (cellValue == cell.getValue()) {
cell.setValue(cellValue + 1);
if (cellValue >= 2) {
cellValue = 2;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.