[英]How to write in cells in GoogleSpreadSheet using app Script?
and sorry for the stupid question. 对这个愚蠢的问题感到抱歉。
I know how to program on VBA for Excel, but I´m having a hard time doing the simplest stuff in Google Spreadsheet and I can´t find any good tutorials on-line. 我知道如何在VBA for Excel上编程,但是我很难在Google Spreadsheet中做最简单的事情,而且我找不到任何在线的好教程。
My question is regarding cells. 我的问题是关于细胞的。 In VBA to write in a cells I would do: 在VBA中写入单元格,我会这样做:
cells(1,1) = 2 //that would write the number 2 in the first row of the first column
In VBA I can also assign a cell to a variable, like: 在VBA中,我还可以将单元格分配给变量,例如:
dim something as long
something = cells(1,1)
How can I apply the same principles in google SpreadSheet? 如何在Google SpreadSheet中应用相同的原则?
Thank you very much! 非常感谢你!
I´ve tried what you guys suggested. 我尝试了你们的建议。 And now I have a follow up question. 现在我有一个后续问题。
I`m trying to modify the cells in a specific range. 我正在尝试在特定范围内修改单元格。 I´ve tried this code: 我尝试了以下代码:
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var board = sheet.getRange(2,2,9,9);
board[0][0].setValue(2);
But apparently I can´t use array notation. 但是显然我不能使用数组符号。 I´m not sure if .setValeu or .getRange are the problem. 我不确定.setValeu或.getRange是问题所在。 But is there a way I can use array notation to chance a cell? 但是,有没有一种方法可以使用数组表示法来对单元格进行赋值?
Thanks Again! 再次感谢!
Try following: 请尝试以下操作:
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var cell = sheet.getRange(1,1);
cell.setValue(2);
It's worthwhile looking at the docs for getRange . 值得看一下getRange的文档 。
getRange(row, column, numRows, numColumns) getRange(行,列,numRows,numColumns)
Returns the range with the top left cell at the given coordinates with the given number of rows and columns. 返回具有给定的行数和列数的给定坐标处左上角单元格的范围。
You can therefore update multiple cells with an array like this: 因此,您可以使用以下数组更新多个单元格:
var sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange(1, 1, numRows, numColumns).setValues(data);
SpreadsheetApp.flush();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.