我在电子表格中列出了可能的图像文件名。我正在尝试获取文件(如果存在)并将其插入名称旁边的单元格中。但是当我致电.hasNext()
时,我收到了一个错误消息。我正在使用的代码是:
function listFilesInFolder(folderName) {
var sheet = SpreadsheetApp.getActiveSheet();
var i = 0;
var numberOfRows = sheet.getLastRow();
for (i=0;i<numberOfRows;i+=1) {
var range = sheet.getRange(i+1,1);
var data = range.getValue();
var file = DriveApp.getFolderById("FOLDER_ID_HERE").searchFiles(data);
if (file.hasNext()) {
var rangeDest =sheet.getRange(i+1,2);
var output = file.next();
rangeDest.setValue("=image(\"https://drive.google.com/uc?export=download&id=" + output.getId() +"\")");
};
};
};
任何想法? 谢谢!
答案 0 :(得分:0)
问题出在这一行:
var file = DriveApp.getFolderById("FOLDER_ID_HERE").searchFiles(data);
应该是:
var searchString = 'title contains "' + data + '"';
var file = DriveApp
.getFolderById("FOLDER_ID_HERE")
.searchFiles(searchString);