gpt4 book ai didi

google-apps-script - Google Picker - 将文件 ID 返回到我的 Google 脚本

转载 作者:行者123 更新时间:2023-12-04 17:21:53 24 4
gpt4 key购买 nike

我有一个相当基本的电子表格,它使用一些 Google 脚本来完成各种任务。我试图为最终用户清理界面,并决定实现 Google Picker。最初,用户必须手动将 CSV 导入电子表格。这里的新目标是通过 Google Picker 选择 CSV,上传,导入,然后删除。我已经有所有的代码可以导入和删除它。我刚刚为选择器编写了代码,它似乎工作正常。但是,我想我只是遗漏了一些小东西,我如何将文件 ID 从 Picker.html 传递回我的 Google 脚本以继续我的过程?

如果有帮助,我现在正在使用 Google 文档中提供的基本回调。我假设这是进行更改的地方。只是不知道该怎么做。

  function pickerCallback(data) {
var action = data[google.picker.Response.ACTION];
if (action == google.picker.Action.PICKED) {
var doc = data[google.picker.Response.DOCUMENTS][0];
var id = doc[google.picker.Document.ID];
var url = doc[google.picker.Document.URL];
var title = doc[google.picker.Document.NAME];
document.getElementById('result').innerHTML =
'<b>You chose:</b><br>Name: <a href="' + url + '">' + title + '</a><br>ID: ' + id;
} else if (action == google.picker.Action.CANCEL) {
document.getElementById('result').innerHTML = 'Picker canceled.';
}
}

最佳答案

这应该可以工作:

在您的 pickerCallback(data) 函数中:

if (data.action == google.picker.Action.PICKED) {
var fileId = data.docs[0].id;
google.script.run
.withSuccessHandler(useData) // this will call the google apps script function in your Code.gs file
.doSomething(fileId); // this is a function in your JavaScript section where you will do something with the code you got from your apps script function
}

function useData(data) {
// do something with the data
}

在 Code.gs 中,创建一个函数来处理来自选择器的输入:
function doSomething(fileId) {
// do an operation in Drive with the fileId
var file = DriveApp.getFileById(fileId);
var fileName = file.getName();
return fileName;
}

关于google-apps-script - Google Picker - 将文件 ID 返回到我的 Google 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23074352/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com