Google Apps脚本使您能够通过其ID或URL来引用表单。
https://developers.google.com/apps-script/reference/forms/form-app
我想遍历其名称中包含特定字符串的所有表单。
我想避免在我继续维护所有表单ID的列表时。表格来来去去,所以我宁愿找到所有表格,然后对它们进行迭代。
我已尝试查看Google Apps脚本网站上的所有文档,但无法找到任何类型的list
方法。
如何获得所有可用表格的清单?
答案 0 :(得分:2)
或者你可以用更简单的方式做到:
function allFormFilesWithStringInTitle() {
// Log the name of every file in the user's Drive that is a form mime type
// whose name contains "Untitled".
//var files = DriveApp.searchFiles('title contains "Untitled"');
var files = DriveApp.searchFiles('mimeType = "application/vnd.google-apps.form" and title contains "Untitled"');
while (files.hasNext()) {
var file = files.next();
Logger.log(file.getName());
Logger.log(file.getMimeType());
}
}
答案 1 :(得分:1)
function goThroughAllForms() {
var formInfo,arrayFormIDs,arrayFormNames,arrayOfIndexNumbers,
allFormIDsWithStringInName,i,searchStr,thisID;
searchStr = "Untitled";
formInfo= getFilesOfType();
arrayFormNames = formInfo[1];
arrayOfIndexNumbers = searchFormNamesForString(arrayFormNames,searchStr);
//Logger.log('searchStr: ' + searchStr)
//Logger.log(arrayOfIndexNumbers)
allFormIDsWithStringInName = [];
arrayFormIDs = formInfo[0];
for (i=0;i<arrayOfIndexNumbers.length;i+=1) {
thisID = arrayFormIDs[arrayOfIndexNumbers[i]];
allFormIDsWithStringInName.push(thisID);
};
Logger.log(allFormIDsWithStringInName)
};
function getFilesOfType() {
var allFormFiles,arrFileName,arrFileID,arrFileUrls,thisFile;
allFormFiles = DriveApp.getFilesByType(MimeType.GOOGLE_FORMS);
arrFileName = [];
arrFileID = [];
arrFileUrls = [];
while (allFormFiles.hasNext()) {
thisFile=allFormFiles.next();
arrFileName.push(thisFile.getName());
arrFileID.push(thisFile.getId());
arrFileUrls.push(thisFile.getUrl());
};
//Logger.log(arrFileName)
return [arrFileID,arrFileName];
};
function searchFormNamesForString(arrayFormNames,searchStr) {
var arrayIndexNumbers,i,L,thisName;
arrayIndexNumbers = [];
L = arrayFormNames.length;
for (i=0;i<L;i+=1){
thisName = arrayFormNames[i];
Logger.log(thisName);
Logger.log('thisName.indexOf(searchStr): ' + thisName.indexOf(searchStr));
if (thisName.indexOf(searchStr) !== -1) {
arrayIndexNumbers.push(i);
};
};
return arrayIndexNumbers;
};