如何通过 App Script 在特定文件夹中创建电子表格 [英] How to Create a Spreadsheet in a particular folder via App Script

查看:28
本文介绍了如何通过 App Script 在特定文件夹中创建电子表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能帮帮我,

我想通过特定文件夹中的 App 脚本创建电子表格.如何做到这一点.

I want to create a Spreadsheet through App Script in a particular folder. How to do that.

目前我的做法如下:

var folder = DocsList.getFolder("MyFolder");
var sheet = SpreadsheetApp.create("MySheet");
var file = DocsList.getFileById(sheet.getId());
file.addToFolder(folder);
file.removeFromFolder(file.getParents()[0]);

它不起作用.......

It is not working.......

推荐答案

由于您无法再使用 DriveApp 创建 Google 文档(文档或电子表格),也无法使用 addToFolder 因为 DocList 已被弃用.只有一种方法可以创建或移动"Google 文档或 Google 电子表格.

Since you can no longer create Google Docs (Docs or SpreadSheets) using DriveApp, nor use addToFolder because DocList is deprecated. There is only one way to create or "move" Google Docs or Google SpreadSheets..

  //"Move" file to folder-------------------------------//
  var fileID = '12123123213321'
  var folderID = '21321312312'
  var file = DriveApp.getFileById(fileID).getName()
  var folder = DriveApp.getFolderById(folderID)
  var newFile = file.makeCopy(file, folder)

  //Remove file from root folder--------------------------------//
  DriveApp.getFileById(fileID).setTrashed(true)

正如您所看到的那样不会移动文件,它会在您想要的文件夹中创建一个同名副本,然后将原始文件移动到垃圾箱.我很确定没有其他方法可以做到这一点.

As you can see this DOES NOT move the file, it makes a copy with the same name in the folder you want and then moves the original file to the trash. I'm pretty sure there is no other way to do this.

这篇关于如何通过 App Script 在特定文件夹中创建电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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