我正在使用 Google 表单收集团队成员的图像,我想确保上传到 Google 表单并保存在 Google 云端硬盘中的每个文件都具有相同的命名约定。
有五个上传文件要求团队成员上传图像的问题。这些文件被放置在 Google Drive 文件夹中,文件名随机,后跟- firstName lastName
. On an 表单提交时触发器我想将用户提供的文件的名称更改为fileUploadQuestionName - firstName lastName
.
我对 Google Apps 脚本还很陌生,我不知道如何去做。任何帮助将不胜感激!
您可以通过以下过程更改提交的每个表单上上传的文件的名称
- 检索最后一个表单响应表单提交时 with
form.getResponses()[LAST FORM SUBMISSION]
- 检索上传文件的 ID
getItemResponses()[QUESTION NUMBER].getResponse()
- 使用 DriveApp 打开文件 ID 并根据需要更改其名称
function myFunction() {
var form=FormApp.getActiveForm();
// returns the total number of form submissions
var length=form.getResponses().length;
//replace QUESTION NUMBER through the index of the question prompting the file upload - keep in mind that the first question has the index 0
var id=form.getResponses()[length-1].getItemResponses()[QUESTION NUMBER].getResponse();
//getResponses()[length-1] retrieves the last form response, accounting for the fact that the first index is zero and hte last length-1
//gets the name of the question
var fileUploadQuestionName=form.getResponses()[length-1].getItemResponses()[QUESTION NUMBER].getItem().getTitle();
//accesses the uploaded file
var file=DriveApp.getFileById(id);
name = file.getName();
//changes the file name
var name = fileUploadQuestionName+' - '+name.split(' - ')[1]
file.setName(name);
}
PS:如果您想更改所有提交文件的后验名称,而不仅仅是最后一个文件的名称 - 您需要循环遍历所有表单响应:
for(var i=0;i<length;i++){
var id=form.getResponses()[i].getItemResponses()[QUESTION NUMBER].getResponse();
...
...
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)