在与当前文件相同的文件夹中创建一个Google电子表格 [英] Create a google spreadsheet in same folder as current file
本文介绍了在与当前文件相同的文件夹中创建一个Google电子表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Google表单脚本,我想在与表单相同的文件夹中创建电子表格.
I have a google form script that I want to create a spreadsheet in the same folder as the form.
var thisFileId = form.getId();
var parentFolder = DriveApp.getFolderById(thisFileId)
spreadsheet = SpreadsheetApp.create(spreadsheetName);
var spreadsheetID = spreadsheet.getId();
var spreasheetFile = DriveApp.getFileById(spreadsheetID);
spreasheetFile.moveTo(parentFolder);
我在最后一行上出现错误:
"异常:无效参数:parent.mimeType"
"Exception: Invalid argument: parent.mimeType"
推荐答案
我相信您的目标如下.
- 您要使用
form.getId()
在同一文件夹中创建新的电子表格.
- You want to create new Spreadsheet to the same folder with
form.getId()
.
- 在脚本中,关于
form.getId()
的变量名from
,如果form
是Google表单,则form.getId()
是Google表单的文件ID.我认为这可能是您遇到问题的原因. - 为了将新的电子表格与
form
放在同一文件夹中,需要检索form
的父文件夹.
- In your script, about the variable name
from
ofform.getId()
, ifform
is the Google Form,form.getId()
is the file ID of Google form. I think that this might be the reason of your issue. - In order to put the new Spreadsheet to the same folder with
form
, it is required to retrieve the parent folder ofform
.
当以上几点反映到您的脚本中时,它如下所示.
When above points are reflected to your script, it becomes as follows.
var parentFolder = DriveApp.getFolderById(thisFileId)
至:
var parentFolder = DriveApp.getFileById(thisFileId).getParents().next();
注意:
- 当将除文件夹ID之外的ID用于
DriveApp.getFolderById(id)
时,似乎没有错误. - It seems that when ID except for the folder ID is used for
DriveApp.getFolderById(id)
, no error occurs.
Note:
这篇关于在与当前文件相同的文件夹中创建一个Google电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文