0
我正在嘗試創建一個腳本,該腳本根據在一系列單元格中輸入的值在另一個工作表中搜索相關數據。然後在相應的相鄰單元中輸入相應的數據。我可以得到儘可能正確的數據,但是我無法將它設置在我的工作表上正確的單元格中。我錯過了什麼嗎?谷歌腳本迭代後的setValue
感謝您從SS2閱讀range3任何援助
function attend() {
var otherSheet = SpreadsheetApp.openById("blahblah").getSheetByName("Students");
var range = otherSheet.getRange("A1:M100");
var students = range.getValues();
var ss = SpreadsheetApp.openById("blahblah2").getSheetByName("Attendance");
var range2 = ss.getRange("B7:D27");
var students2 = range2.getValues();
var range3 = ss.getRange("E7:E27");
var classPack = range3.getValues();
for (var u = 0; u < students2.length; u++){
for (var i = 0; i < students.length; i++) {
if (students2[u][0] == "x") {
if (students[i][0] == "x") {
if (students[i][10] > 0){
var data = students[i][10];
students2[u][4] = data;
range3.setValues(classPack);
}
}
}
}
}
}
修改代碼
function onEdit() {
var otherSheet = SpreadsheetApp.openById("blahblah").getSheetByName("Students")
var range = otherSheet.getRange("A1:M100")
var students = range.getValues()
var ss = SpreadsheetApp.openById("blahblah2").getSheetByName("Attendance")
var range2 = ss.getRange("B7:G27")
var students2 = range2.getValues()
for (var u = 0; u < students2.length; u++){
if (students2[u][0] == "x") {
for (var i = 0; i < students.length; i++) {
if (students[i][0] == "x") {
var classPack = students[i][10]
var membership = students[i][7]
var free = students[i][8]
students2[u][3] = classPack;
students2[u][4] = membership;
students2[u][5] = free;
range2.setValues(students2);
}
}
}
}
}
LOl我只是想我自己,但你打它的權利。謝謝。我的修改後的代碼添加在上面 – 2013-04-29 23:01:28