Google drive api Google代码(驱动器)在父文件夹中创建文件/覆盖父文件夹中的现有文件
所以我创建了一个简单的google代码,将工作表导出为json,我想知道是否有一种简单的方法:Google drive api Google代码(驱动器)在父文件夹中创建文件/覆盖父文件夹中的现有文件,google-drive-api,drive,Google Drive Api,Drive,所以我创建了一个简单的google代码,将工作表导出为json,我想知道是否有一种简单的方法: 将文件导出到运行该文件的脚本所在的工作表所在的文件夹中 覆盖已存在的文件(也在工作表脚本所在的同一文件夹中) 干杯没有简单的方法,但以下是方法(我假设您使用的是应用程序脚本): 获取电子表格的文件id 获取其父文件夹-可以有多个- 查看是否存在名称为的现有文件-可以有多个- 如果存在,请设置其内容 如果它不存在,创建它- thanx向Ian提供研究链接,使其发挥作用:) 如果其他人也需要同
- 将文件导出到运行该文件的脚本所在的工作表所在的文件夹中
- 覆盖已存在的文件(也在工作表脚本所在的同一文件夹中)
干杯没有简单的方法,但以下是方法(我假设您使用的是应用程序脚本):
thanx向Ian提供研究链接,使其发挥作用:) 如果其他人也需要同样的东西,这里有一个片段
var _ID = SpreadsheetApp.getActiveSpreadsheet().getId();
var _sheet = SpreadsheetApp.getActiveSpreadsheet();
var _file = DriveApp.getFolderById(_ID);
var _folder = _file.getParents().next();
var _parentFolder = _file.getParents().next();
var _existingJsons = _parentFolder.getFilesByName(sheet.getName()+".json");
// if .json with the same name already exists in this directory, just overwrite content
if (_existingJsons.hasNext()){
while (_existingJsons.hasNext() ){
var _json = _existingJsons.next();
_json.setContent(output);
Logger.log(_json.getName());
}
}
// if not, create new one, and move it in the same folder sheet is in
else {
var _json = DriveApp.createFile(sheet.getName()+".json", output, MimeType.PLAIN_TEXT);
_json.makeCopy(_parentFolder);
_json.setTrashed(true);
}
thanx的链接,将尽快尝试