我們的電子表格只有 2 列用于匹配學生和導師的資料。第一列是學生資訊。第二個有“是”或“否”與導師的可用性。我們希望這樣,在導師從 Google 表格中選擇學生后,他們在作業表上被標記為“否”,并且他們的資訊從表格選項中洗掉:
function updateCHECKBOX() {
const ws = SpreadsheetApp.getActiveSpreadsheet();
const studentsSheet = ws.getSheetByName("Students")
const students =studentsSheet.getRange(2,1,studentsSheet.getLastRow(),1).getDisplayValues()
const studentsList = students.filter(row=>row[1]=="YES").map(row => row[0])
const form = FormApp.openById("1FvM3v3Cg1b2lSRTJpp3V_pl369wkJoAS7ypO0J4AhQg")
const studentsQuestion = form.getItemById ("2116012197")
studentsQuestion.asMultipleChoiceItem().setChoiceValues(studentsList)
}
但是,當我們運行最終代碼時,我們得到“錯誤,例外:陣列為空:值”。表格和表格的圖片如下:
“學生”表
谷歌表格
uj5u.com熱心網友回復:
如果你只有兩列資料
也許這個:
const datesList = dates.filter(row=>row[2]=="FREE").map(row => row[0])
應該是這樣的:
const datesList = dates.filter(row=>row[1]=="FREE").map(row => row[0])
我必須查看電子表格和更多代碼才能確定。
弄清楚要保留哪些行應該相當簡單?
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/432778.html
標籤:谷歌应用脚本
