在与当前文件相同的文件夹中创建一个Google电子表格 [英] Create a google spreadsheet in same folder as current file

查看:59
本文介绍了在与当前文件相同的文件夹中创建一个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 of form.getId(), if form 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 of form.

当以上几点反映到您的脚本中时,它如下所示.

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)时,似乎没有错误.
  • Note:

    • It seems that when ID except for the folder ID is used for DriveApp.getFolderById(id), no error occurs.
    • 这篇关于在与当前文件相同的文件夹中创建一个Google电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆