If it isn't immediately apparent by the question, I am pretty new to Google Apps Script. I'm trying to write a Spreadsheets function that runs through each row of a form submission sheet in a workbook and update a second sheet/range (in the same workbook) based on the values of the cells in the first using a for loop. However, nothing happens when I run the function.
如果问题没有立即显现,我对Google Apps脚本很新。我正在尝试编写一个Spreadsheets函数,该函数遍历工作簿中表单提交表的每一行,并使用for循环基于第一个单元格中的单元格值更新第二个工作表/范围(在同一工作簿中)。但是,当我运行该功能时没有任何反应。
I'm pretty sure the error is in how I'm defining the ranges in question, but I'm not 100% sure. Here's a modified version of what I've written:
我很确定错误在于我如何定义相关范围,但我不是百分百肯定。这是我写的修改版本:
function update() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var secondSheet = ss.getSheets()[1];
var submissionSheet = ss.getSheets()[0];
var secondRowEnd = secondSheet.getLastRow();
var submissionRowEnd = submissionSheet.getLastRow();
var secondColumnEnd = secondSheet.getLastColumn();
var submissionColumnEnd = submissionSheet.getLastColumn(); //used to define ranges dynamically
var secondRange = secondSheet.getValues();
var submissionRange = submissionSheet.getValues();
for(var i = 2; i <= submissionRowEnd; i++) {
var rock = secondRange.getCell(i, 1).getValue();
var paper = secondRange.getCell(i, 2).getValue();
var scissors = secondRange.getCell(i, 3).getValue();
var status = secondRange.getCell(i, 4).getValue();
var forStatus = secondRange.getCell(i, 5).getValue();
if (status === "Do X!") {
for(var j = 2; j <= submissionRowEnd; j++) {
var jrock = submissionRange.getCell(j, 1).getValue();
var jpaper = submissionRange.getCell(j, 2).getValue();
var jscissors = submissionRange.getCell(j, 3).getValue();
var jstatus = submissionRange.getCell(j, 4).getValue();
if (status === forStatus) {
jrock.setValue(rock);
jpaper.setValue(paper);
jscissors.setValue(scissors);
} else { /*do nothing*/ }
}
}
}
I've been staring at slightly different versions of this code for weeks now, so any and all eyes on this would be greatly, greatly appreciated!
几个星期以来,我一直在盯着这个代码略有不同的版本,所以任何和所有人都会非常感激!
1 个解决方案
#1
2
Just checkout out the Apps Script API reference for the Spreadsheet Service. All the functions are documented there. Here are links to descriptions of the methods you need:
只需签出电子表格服务的Apps Script API参考。所有功能都记录在那里。以下是您需要的方法说明的链接:
getRange() has multiple implementations.
getRange()有多个实现。
- Sheet.getRange(row, column)
- Sheet.getRange(row, column, numRows)
- Sheet.getRange(row, column, numRows, numColumns)
- Sheet.getRange(a1notation)
Sheet.getRange(row,column,numRows)
Sheet.getRange(row,column,numRows,numColumns)
#1
2
Just checkout out the Apps Script API reference for the Spreadsheet Service. All the functions are documented there. Here are links to descriptions of the methods you need:
只需签出电子表格服务的Apps Script API参考。所有功能都记录在那里。以下是您需要的方法说明的链接:
getRange() has multiple implementations.
getRange()有多个实现。
- Sheet.getRange(row, column)
- Sheet.getRange(row, column, numRows)
- Sheet.getRange(row, column, numRows, numColumns)
- Sheet.getRange(a1notation)
Sheet.getRange(row,column,numRows)
Sheet.getRange(row,column,numRows,numColumns)