![](/img/trans.png)
[英]I am trying to unlink, and delete a google form to google sheet link and then relink it to a new sheet with the same name
[英]I'm trying to use this function (which I found on a website) to link google form questions with a spread sheet but i keep getting error in line 4
我正在嘗試使用此 function(我在網站上找到)將 google 表單問題與電子表格鏈接,但我在第 4 行錯誤嘗試執行 myFunction,但無法保存。
function getDataFromGoogleSheets () {
const ss = SpreadsheetApp.openById('1xYldb3csabrznjvapWPlIPAkEVQAyKlLQGzl810mG3Y');
const sheet = ss.getSheetByName("clinic");
const [header, ...data] = sheet.getDataRange().getDisplayValues();
const choices = {};
header.forEach(function(title, index) {
choices[title] = data.map((row) => row[index]).filter((e) => e!=="");
});
return choices;
}
function populateGoogleForms() {
const GOOGLE_FORM_ID = '1jg4vooSWG4BY7z_9tMQV5aVaTOGeauC3ad3vsfvhGgk';
const googleForm = FormApp.openById(GOOGLE_FORM_ID);
const items = googleForm.getItems();
const choices = getDataFromGoogleSheets;//<======== Missing () in function call
items.forEach(function(item){
const itemTitle = item.getTitle();
if(itemTitle in choices){
const itemType = item.getType();
switch (itemType) {
case FormApp.ItemType.CHECKBOX:
item.asCheckboxItem().setChoiceValues(choices[itemTitle]);
break;
case FormApp.ItemType.LIST:
item.asListItem().setChoiceValues(choices[itemTitle]);
break;
case FormApp.ItemType.MULTIPLE_CHOICE:
item.asMultipleChoiceItem().setChoiceValues(choices[itemTitle]);
break;
default:
Logger.log('ignore question',itemTitle)
}
}
});
ss.toast('Google Form Updated !!');
}
這個const choices = getDataFromGoogleSheets;
需要是這個const choices = getDataFromGoogleSheets();
這是使用新編輯器的常見錯誤。 我的猜測是編寫新編輯器的人從未使用過它。 如果他們這樣做了,他們會更傾向於改變它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.