Google Sheets API:创建电子表格或将电子表格移动到文件夹中 [英] Google Sheets API: Create or move Spreadsheet into Folder
本文介绍了Google Sheets API:创建电子表格或将电子表格移动到文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在指定的文件夹中创建电子表格,还是必须使用Drive API来随后将其移动?
Is it possible to create a Spreadsheet in a specified Folder or do I have to use the Drive API to move it afterwards?
推荐答案
我有点晚了,但是我发现的方式不需要复制/删除文件.您只需删除并添加父母即可.我的代码是用Ruby而不是JS编写的,但是我确定类似的东西存在.
I'm a little late but the way I found doesn't require copying/deleting the file. You simply remove and add parents. My code is in Ruby instead of JS but I'm sure something similar exists.
file = service.get_file(file_id,fields: 'parents')
service.update_file(
file_id,
file
remove_parents: file.parents,
add_parents: new_folder_id,
fields: 'id,parents'
)
搜索了驱动器api文档几分钟后,我发现下面的代码用于Node.JS将文件移动到特定文件夹中.希望这会有所帮助.
After a few minutes of searching the drive api docs, I found the code below for Node.JS to move a file into a specific folder. Hope this helps.
fileId = '1sTWaJ_j7PkjzaBWtNc3IzovK5hQf21FbOw9yLeeLPNQ'
folderId = '0BwwA4oUTeiV1TGRPeTVjaWRDY1E'
// Retrieve the existing parents to remove
drive.files.get({
fileId: fileId,
fields: 'parents'
}, function(err, file) {
if (err) {
// Handle error
console.log(err);
} else {
// Move the file to the new folder
var previousParents = file.parents.join(',');
drive.files.update({
fileId: fileId,
addParents: folderId,
removeParents: previousParents,
fields: 'id, parents'
}, function(err, file) {
if(err) {
// Handle error
} else {
// File moved.
}
});
}
});
这篇关于Google Sheets API:创建电子表格或将电子表格移动到文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文