学生成绩册.由于“拒绝访问:DriveApp"而无法完成脚本

2023-01-30前端开发问题
8

本文介绍了学生成绩册.由于“拒绝访问:DriveApp"而无法完成脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我的脚本从工作表学生"中获取 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

  1. 如果您在 getEditors() 或 getViewers() 列表中,我有解决方案:只需撤销您自己的权限即可.file.revokePermissions(Session.getActiveUser());文件将消失.
  2. 如果文件设置了 isShareableByEditors(),则示例 1 不起作用 - 如果它为false",则您无法执行任何操作.
  3. 如果您已将文件添加到您的驱动器,该文件可供拥有链接的所有人公开访问,则您无法撤消权限,因为您没有权限.应用脚本返回访问被拒绝.所以,我认为我可以 setTrashed(true).我错了.Google 还返回拒绝访问:DriveAp.

在案例 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"而无法完成脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

ajax请求获取json数据并处理的实例代码
ajax请求获取json数据并处理的实例代码 $.ajax({ type: 'GET', url: 'https://localhost:44369/UserInfo/EditUserJson',//请求数据 data: json,//传递数据 //dataType:'json/text',//预计服务器返回的类型 timeout: 3000,//请求超时的时间 //回调函数传参 suc...
2024-11-22 前端开发问题
215

js删除数组中指定元素的5种方法
在JavaScript中,我们有多种方法可以删除数组中的指定元素。以下给出了5种常见的方法并提供了相应的代码示例: 1.使用splice()方法: let array = [0, 1, 2, 3, 4, 5];let index = array.indexOf(2);if (index -1) { array.splice(index, 1);}// array = [0,...
2024-11-22 前端开发问题
182

layui 实现实时刷新一个外部的div
主页面上显示了一个合计,在删除和增加的时候需要更改这个总套数的值: //html代码div class="layui-inline layui-show-xs-block" style="margin-left: 10px" id="sumDiv"spanSOP合计:/spanspan${totalNum}/spanspan套/span/div 于是在我们删除这个条数据后,...
2024-11-14 前端开发问题
156

layui laydate日期时间范围,时间默认设定为23:59:59
在Layui中,如果你想设置日期时间选择器(datetime)的默认结束时间为当天的23:59:59,你可以使用如下代码: laydate.render({ elem: '#test10' ,type: 'datetime' ,range: true ,max: '{:date("Y-m-d 23:59:59")}' ,ready: function(date){ $(".layui-laydat...
2024-10-24 前端开发问题
279

JavaScript小数运算出现多位的解决办法
在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会...
2024-10-18 前端开发问题
301

jQuery怎么动态向页面添加代码?
append() 方法在被选元素的结尾(仍然在内部)插入指定内容。 语法: $(selector).append( content ) var creatPrintList = function(data){ var innerHtml = ""; for(var i =0;i data.length;i++){ innerHtml +="li class='contentLi'"; innerHtml +="a href...
2024-10-18 前端开发问题
125