为什么 webapp 以我的身份执行,任何人都可以访问,显示 effectiveUser 和 activeUser 是编辑者,而不是所有者?
因此,我有一些绑定到电子表格的函数,这些函数可以对不受编辑器保护的范围进行修改。当编辑者单击电子表格上的按钮时,将运行这些函数。这些函数还从其他文件中获取编辑者无权访问的数据。 因此,根据下面的评论,它必须部署为一个 Web 应用程序,由我运行并由任何人访问。
我的理解是其中必须有一个 doGet()
函数,并且要调用 Web 应用程序 url。但是,我不知道在哪里添加这个 doGet()
函数,如下所示。
现有函数的示例:
file: globals.gs
,电子表格外部的数据被引入到文件
const CAD_PRODUTO = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const config = {
get ssBDCadProd() {
delete this.ssBDCadProd;
return (this.ssBDCadProd = SpreadsheetApp.openById(CAD_PRODUTO));
}
const sheetBDCadProd = config.ssBDCadProd.getSheetByName('CadProduto');
中 电子表格中的函数,它根据外部文件中的数据创建一个新数字:
function gerarRef() {
try {
const response = Browser.msgBox('Do you want to create a new record?', Browser.Buttons.YES_NO);
if (response == 'no') {
return;
} else {
let ref = 0;
const refExistentes = sheetBDCadProd.getRange(2, 1, sheetBDCadProd.getLastRow(), 1).getValues(); //Calls other file
let ultRef = Math.max(...refExistentes);
Logger.log('Ult.: ' + ultRef)
if (ultRef == 0 || ultRef == '') {
ref = 10000;
} else {
ref += ultRef + 1;
}
const refRng = sheetCadProd.getRange('B5').setValue(ref);
refRng.offset(0, 2).activate();
}
} catch (err) {
Browser.msgBox('Ocorreu um erro: ' + err);
}
}
除了上面的功能之外,我还有很多其他的功能。 我该如何应用网络应用
方法?
谢谢一百万!
So, I have some functions bounded to a spreadsheet, which makes modifications to ranges protected from editors. The functions are to be run as the editors click on buttons on the spreadsheet. These functions also bring data from other files, which editors don't have access to.
So, as per comments below, it would have to be deployed as a web app
, run by me and accessed by anyone.
My understanding is there must be a doGet()
function in it and the web app url is to be called. However, I don't know where to add this doGet()
function as suggested below.
Examples of existing functions:
file: globals.gs
, which is where data outside of the spreadsheet are brought into the file
const CAD_PRODUTO = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const config = {
get ssBDCadProd() {
delete this.ssBDCadProd;
return (this.ssBDCadProd = SpreadsheetApp.openById(CAD_PRODUTO));
}
const sheetBDCadProd = config.ssBDCadProd.getSheetByName('CadProduto');
Function sitting in the spreadsheet, which creates a new number based on data in an external file:
function gerarRef() {
try {
const response = Browser.msgBox('Do you want to create a new record?', Browser.Buttons.YES_NO);
if (response == 'no') {
return;
} else {
let ref = 0;
const refExistentes = sheetBDCadProd.getRange(2, 1, sheetBDCadProd.getLastRow(), 1).getValues(); //Calls other file
let ultRef = Math.max(...refExistentes);
Logger.log('Ult.: ' + ultRef)
if (ultRef == 0 || ultRef == '') {
ref = 10000;
} else {
ref += ultRef + 1;
}
const refRng = sheetCadProd.getRange('B5').setValue(ref);
refRng.offset(0, 2).activate();
}
} catch (err) {
Browser.msgBox('Ocorreu um erro: ' + err);
}
}
Besides the functions above, I got many others.
How can I then apply the web app
approach?
Thanks a million!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“以我的身份运行”和“任何人”等 Web 应用部署设置仅对
doGet
和doPost
函数有效,并且仅当它们被 HTTP 请求调用时(当它们是通过使用 Web 应用程序 URL 来调用的)。如果您通过插入绘图并为其分配函数来在电子表格上设置按钮,则网络应用部署设置不会对直接调用 Google Apps 脚本服务(例如 SpreadsheetApp)的函数产生任何影响,但如果该函数可能会起作用使用 UrlFetchApp 服务向您的 Web 应用程序发出 HTTP 请求。
下面是一个过于简化的 Google Apps 脚本服务器端代码 (.gs),用于调用网络应用程序:
一种更简单的方法可能是使用可安装的触发器,因为它不需要处理另一个“复杂层”,因为它不需要处理另一个“复杂层”。需要向您的项目添加另一个服务 (UrlFetchApp),则无需在每次更新代码时部署 Web 应用程序并制作新版本,但如果您希望至少保留授权范围这编辑,您将不得不使用网络应用程序方法。
相关
The web app deployment settings like "Run as me" and "By Anyone" only have effect over
doGet
anddoPost
functions, and only when they are called by HTTP requests (when they are called by using the web app URL).If you have set a button on a spreadsheet by inserting a drawing and assigning a function to it, the web app deployment settings will not have any effect over a function that directly calls the Google Apps Scripts services like SpreadsheetApp, but might work if the function use the UrlFetchApp service to make the HTTP request to your web app.
Here is an oversimplified Google Apps Script server side code (.gs) to make a call to a web app:
An easier approach might be to use an installable trigger as it's not required to deal with another "complexity layer" as it doesn't require to add another service to your project (UrlFetchApp), it will not be necessary to deploy a web-app and make a new version every time that you update your code, but if you want to keep at minimum the scopes to be authorized by the editors, you will have to use the web app approach.
Related