我的脚本从工作表学生"中获取 35 个学生姓名.然后找到带有他们名字的正确文件夹(即'Smith Peter'),删除旧的pdf文档,其中旧成绩保留他们的名字(即'Smith Peter.pdf')并将新制作的pdf保存到文件夹('Smith Peter')带有新成绩的文档('Smith Peter.pdf').并从名单中带走另一个学生.
My script takes 35 student names from the Sheet 'Studenti'. Then finds the proper folder with their name (i.e. 'Smith Peter'), removes old pdf document with old grades holding their name (i.e 'Smith Peter.pdf') and saves to the folder ('Smith Peter') a newly made pdf document with new grades ('Smith Peter.pdf'). And goes to take another student from the list.
问题:在 1,2 或 3 次迭代后,脚本停止说:访问被拒绝:DriveApp.(第 22 行,文件代码":files.next().setTrashed(true);).一周前脚本运行没有问题,我尝试在这里更改名称、文件夹、目的地、源表和检查建议.但没有成功.我不知道第22行有什么问题.请帮忙!
The problem: after 1,2 or 3 iterations the script stops saying: Access denied: DriveApp. (line 22, file "Code": files.next().setTrashed(true);). A week ago the script was working without problems, I tried to change names, folders, destinations, source sheets and checked advice here. But no success. I don't know what is wrong with the line 22. Please help!
附上代码
执行脚本(显示脚本停止的位置)
Execution transcript (shows where the script has stopped)
function generatePdf() {
var report = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); // Gradebook ready to save as pdf
var zasobnik = SpreadsheetApp.openById('1eygLDH0iJoXfcVOMIin0hnKpMF59HszmXZosPKvwYWc');
var zasobsheet = zasobnik.getSheetByName("Studenti"); // list of 35 students with names, Folder IDs
var data = zasobsheet.getDataRange().getValues();
for (var i = 1; i < data.length; i++){
report.getRange('B2').setValue(data[i][0]); // setting student's name in a gradebook (first column)
report.getRange('B3').setValue(' '); // just to jump from B2 to B3
var pdf = DriveApp.getFileById('1WHwm7xK28Orj22RxaKWEsCl3UWvWxYUhRg4ZGf87-GQ'); // ID of Gradebook (IF of ActiveSpreadsheet)
var theBlob = pdf.getBlob().getAs('application/pdf').setName(data[i][0] + ".pdf");
var folder = DriveApp.getFolderById(data[i][2]); // third column
var files = DriveApp.getFilesByName(data[i][0] + ".pdf"); // pdf with old grades
while (files.hasNext()) {
files.next().setTrashed(true);
}
var newFile = folder.createFile(theBlob); // creating pdf with new grades in the student's folder
}
}
我也遇到了同样的问题,即我不拥有的垃圾文件.我发现了
I have the same problem with trashing files, that I don't own. I found that
在案例 2 和 3 到应用程序脚本的情况下,我没有找到从驱动器中删除不需要的文件的方法.但是仍然可以通过单击它们并选择删除"选项来实现.
I didn't find a way to remove unwanted files from my drive in case 2 and 3 thru apps script. But it's still possible by clicking on them and choosing option "Remove".
这篇关于学生成绩册.由于“拒绝访问:DriveApp"而无法完成脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!