我需要搜索活动电子表格的父文件夹,以找到具有指定名称“ event_form_responses”的文件,以从中获取值并在另一张工作表中使用这些值。调试下面的脚本将返回以下错误:“在对象export_form_responses中找不到函数getSheetByName。”我在做什么错了?
function SSbyName(){
//get current folder id
var ss = SpreadsheetApp.getActive();
var directParents = DriveApp.getFileById(ss.getId()).getParents();
while( directParents.hasNext() ) {
var folder = directParents.next();
var folderId = folder.getId();
//get files in folder
var parent = DriveApp.getFolderById(folderId);
var search = 'title contains "export_form_responses"';
var specificFile = parent.searchFiles(search);
while (specificFile.hasNext()) {
var file = specificFile.next();
var filesheet = file.getSheetByName("Sheet1");
var responserow = filesheet.getLastRow();
var responsecolumn = filesheet.getLastColumn();
var rawform = ss.getSheetByName("RAWFORM");
var target = rawform.getLastRow();
var content = filesheet.getRange(responserow, 1, 1, responsecolumn).getValues();
rawform.getRange(1, 1, 1, responsecolumn).setValues(content);
}
}
}
答案 0 :(得分:2)
var filesheet = file.getSheetByName("Sheet1");
此行似乎是错误的,因为文件对象(驱动器File class的文件)没有方法“ getSheetByName”。尝试改用以下代码:
var filesheet = SpreadsheetApp.openById(file.getId()).getSheetByName("Sheet1");