[英]Populate specific column in google sheet using google script
I'm using google script in google sheet in order to populate the cell with data that I entered.我在谷歌表中使用谷歌脚本,以便用我输入的数据填充单元格。 First I made a form by using html where I store data I entered as object in html (image below).首先,我使用 html 制作了一个表格,其中我将输入为 object 的数据存储在 html 中(下图)。
then i call the data I stored in html code with javascript in order to populate the targeted sheet(the last row of the first column)(image below), and it worked.然后我用 javascript 调用我存储在 html 代码中的数据,以填充目标工作表(第一列的最后一行)(下图),它起作用了。
But then, I created the same form with the same code html but for now I want to populate the last row of the second column.但是,我用相同的代码 html 创建了相同的表单,但现在我想填充第二列的最后一行。 I'm trying using the same code appendRow ([null,data.name]), but the problem is it will populate the last row of the sheet.我正在尝试使用相同的代码appendRow ([null,data.name]),但问题是它将填充工作表的最后一行。 I tried to use getRange then setValues but it doesnt work.我尝试使用getRange然后setValues但它不起作用。
Please help请帮忙
Try changing the last row in 'appenData' to尝试将“appenData”中的最后一行更改为
ws.getRange(ws.getLastRow() + 1, 2).setValue(data.name);
You can refer to this sample code:你可以参考这个示例代码:
function appendToColumn() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("trial");
var data = "Testing";
//Get the column where you want to append the data
var range = sheet.getRange("B1:B").getValues().flat();
var row = range.filter(String).length;
Logger.log(row);
sheet.getRange(row+1,2).setValue(data);
}
array.flat()
to change 2-d array to 1-d array获取它的值,使用array.flat()
将二维数组更改为一维数组array.filter()
and get its length使用array.filter()
删除空单元格值并获取其长度Before:前:
After:后:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.