0
我正在嘗試使谷歌表格與谷歌表單鏈接類註冊。隨着過程的進行,他們希望學生選擇課程,然後讓這些課程通過老師獲得通過或拒絕。我目前遇到的唯一問題是將數據分成不同的表格,具體取決於表單提交後他們擁有哪些教師,最近我發現了一個可以像這樣排序的代碼,但必須有一些用戶輸入,而不是表單響應這個工作:通過谷歌表格註冊類
有沒有什麼辦法讓它自動移動到一個新的工作表,如果用戶按下表單上的「提交表單」按鈕並提交它。
/**
* Moves row of data to another spreadsheet based on criteria in column 6 to sheet with same name as the value in column 4.
*/
function onEdit(e) {
// see Sheet event objects docs
// https://developers.google.com/apps-script/guides/triggers/events#google_sheets_events
var ss = e.source;
var s = ss.getActiveSheet();
var r = e.range;
// to let you modify where the action and move columns are in the form responses sheet
var actionCol = 4;
var nameCol = 6;
// Get the row and column of the active cell.
var rowIndex = r.getRowIndex();
var colIndex = r.getColumnIndex();
// Get the number of columns in the active sheet.
// -1 to drop our action/status column
var colNumber = s.getLastColumn()-1;
// if our action/status col is changed to ok do stuff
if (e.value == "submit form" && colIndex == actionCol) {
// get our target sheet name - in this example we are using the priority column
var targetSheet = s.getRange(rowIndex, nameCol).getValue();
// if the sheet exists do more stuff
if (ss.getSheetByName(targetSheet)) {
// set our target sheet and target range
var targetSheet = ss.getSheetByName(targetSheet);
var targetRange = targetSheet.getRange(targetSheet.getLastRow()+1, 1, 1, colNumber);
// get our source range/row
var sourceRange = s.getRange(rowIndex, 1, 1, colNumber);
// new sheets says: 'Cannot cut from form data. Use copy instead.'
sourceRange.copyTo(targetRange);
}
}
}
我希望是有道理的, 約瑟夫