使用电子表格中的单元格在Google驱动器上命名文件 [英] naming a file on Google drive using a cell in spreadsheet
问题描述
我制作了一个Google表单来上传文件.我想通过使用表单中的条目或电子表格中的单元格内容来自动更改文件名.这可能吗?
I have made a Google form that uploads a file. I want to automatically change the name of the file by using an entry from the form, or a cell content in the spreadsheet. Is this possible?
推荐答案
使用onFormSubmit事件更改上传文件的名称
将其与表格的链接工作表一起放在电子表格中
Put this in the spreadsheet with the linked sheet for your form
function onFormSubmit(e) {
var ft=e.values.slice(1);//this removes the timestamp
var fA=ft[0].split(',');//this splits the file url's into an array
for(var i=0;i<fA.length;i++) {
var file=DriveApp.getFileById(fA[i].slice(fA[i].indexOf("=")+1));//get file by id by getting the id from the file.
var t=Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "HHmmss"); //add the date to the filename
file.setName(Utilities.formatString('FileName-%s',t));//set the filename
Utilities.sleep(2000);//I added this to insure that the filenames would bee different.
}
}
我的表单如下:
第一列是时间戳,第二列是上传文件的网址,以逗号分隔.
The first column is a timestamp and the second column are the urls of the uploaded files in a comma delimited string.
files文件夹被加载到创建表单的文件夹的子文件夹中,该文件夹的名称为Form Title +(File Responses)",文件文件夹的名称为Question Name +(File Responses)". /p>
The files folder is loaded into a sub folder of the folder where the form was created that folder was named Form Title + " (File Responses)" and the files folder is named Question Name + " (File Responses)".
这篇关于使用电子表格中的单元格在Google驱动器上命名文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!