我有一张包含问题的表格
- 提单号
- 进口商代码
- 上传文件
每个用户提交回答时,文件应保存在不同的文件夹中,文件夹名称应为问题“BL编号”的输入值。我们怎样才能使它成为可能?
这在很大程度上取决于您的表单的外观。
这是一个如何完成的示例。
假设您有一个非常简单的表单,如下所示:
它有两个“namedValues”:Folder
and File
,它们将在下面的脚本中使用。
下一步:您必须将“链接”电子表格添加到表单中。
在此电子表格中,您必须添加以下脚本:
// names and IDs of your destination folders
var folders = {
'aaa' : '###', // <-- you have to change ### with a real ID
'bbb' : '###',
'ccc' : '###'
}
function move_file_to_folder(e) {
// get folder ID from folders object
var folder_id = folders[e.namedValues['Folder'][0]]; // <-- the name from the named value 'Folder'
// get file ID from the form
var file_id = e.namedValues['File'][0].split('id=')[1]; // <-- the url from the named value 'File'
// move the file into the folder
DriveApp.getFileById(file_id).moveTo(DriveApp.getFolderById(folder_id));
}
// this function should be run just once to install the trigger
function install_OnFormSubmitTrigger() {
var ss = SpreadsheetApp.getActive();
ScriptApp.newTrigger('move_file_to_folder')
.forSpreadsheet(ss)
.onFormSubmit()
.create();
}
之后你必须运行该函数install_OnFormSubmitTrigger()
安装触发器。
运行该函数可能是有意义的move_file_to_folder()
以及,以获得适当的访问权限。它会给你一个错误。别介意。保持冷静并进行。
现在,每次您提交表单时,上传的文件都会进入具有各自名称的文件夹(在我的示例中为“aaa”、“bbb”、“ccc”)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)