我正在开展一个项目,我每天都试图通过新工作表来获取自动更新信息。新工作表将被删除在同一文件夹中,并且每天都会被赋予相同的名称。但是,我需要每天获取新的表单键以使用新表单导入数据运行代码。
我的搜索文件夹功能中遇到类型错误,告诉我它无法在对象中找到函数getId"每日" (我的资料单)。如果有人可以告诉我我的错误或建议更好的方法来获取,存储然后在第31行应用密钥ID那将是伟大的!
var counter = 0;
var files = [];
function searchFolder() {
var folderId = '0B6wmHZ5c0fzfTjI1bFpKOHI3N3M'; // test folder
// Log the name of every file in the folder.
var filesN = DriveApp.getFolderById(folderId).getFiles(); //log files in folder
while (filesN.hasNext())
files.push(filesN.next().getName().getId());
}
function autoUpdate() { //updates monthly from newly imported daily
if (counter == 1) { //counter is made to be 1 when day is uploaded to monthly
var ss = SpreadsheetApp.openById("1lH9Y12P2Q2OFndIJoAU48ePggXFc9WGcWjolZMcABoc");
//defines target spreadsheet ie monthly
SpreadsheetApp.setActiveSpreadsheet(ss); //sets target spreadsheet as
active
var range = ss.getRange("A1:A1"); //sets range in target. ONLY CHOOSE ONE
CELL FOR IMPORTRANGE - IF MORE THAN 1 IS CHOSEN YOU WILL GET A# REF
ERROR BECAUSE IT WILL PUT IMPORTRANGE IN ALL CELLS
range.activate; // activates range
range.setValue('=IMPORTRANGE("1hVv6ldHEaCCI_uptr0MpzAyP60x7on8YR_brWwWXTWo","she et1!A1:167")');
counter = (counter - 1)
}
}
function timeStamp() {
if (files == "Daily") {
counter = (counter + 1)
}
}
searchFolder();
timeStamp();
autoUpdate();
答案 0 :(得分:1)
您正在呼叫filesN.next().getName().getId()
。
filesN.next()
会返回File
object,但File#getName
会返回一个字符串。
正确的功能是File#getId
:
while (filesN.hasNext())
files.push(filesN.next().getId());