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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.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,很抱歉问了这个愚蠢的问题 我知道如何在VBA for Excel上编程,但我很难在Google电子表格中完成最简单的工作,而且我在网上找不到任何好的教程 我的问题是关于细胞的。在VBA中,要在单元格中写入,我将执行以下操作: cells(1,1) = 2 //that would write the number 2 in the first row of the first column 在VBA中,我还可以将单元格指定给变量,如: dim something as long somet

很抱歉问了这个愚蠢的问题

我知道如何在VBA for Excel上编程,但我很难在Google电子表格中完成最简单的工作,而且我在网上找不到任何好的教程

我的问题是关于细胞的。在VBA中,要在单元格中写入,我将执行以下操作:

cells(1,1) = 2 //that would write the number 2 in the first row of the first column  
在VBA中,我还可以将单元格指定给变量,如:

dim something as long
something = cells(1,1)
如何在谷歌电子表格中应用相同的原则

多谢各位

我已经试过你们的建议了。现在我有一个后续问题

我正试图修改特定范围内的单元格。我试过这个代码:

var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var board = sheet.getRange(2,2,9,9);
board[0][0].setValue(2);
但显然我不能使用数组表示法。我不确定是.setValeu还是.getRange有问题。但是有没有一种方法可以用数组符号来计算一个单元格的概率呢

再次感谢

尝试以下操作:

var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var cell = sheet.getRange(1,1);
cell.setValue(2);

这本书值得一看

getRange(行、列、numRows、numColumns)

返回左上角单元格位于给定坐标处的范围 给定的行数和列数

因此,可以使用如下数组更新多个单元格:

var sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange(1, 1, numRows, numColumns).setValues(data);
SpreadsheetApp.flush();

请在谷歌上搜索“谷歌应用程序脚本”,并首先阅读那里的教程。查看电子表格应用程序。我知道我看起来很懒。。。。但我发誓事实并非如此。我已经完成了基本的教程,但我仍然无法掌握窍门。。。很抱歉,我的学习速度太慢了……当使用setValue()(不带S)时,您不需要定义包含4个参数的范围,只需要定义单元格坐标。请更新您的答案。thx