Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 有没有办法让appscript使用一个人拥有的电子表格作为另一个用户查找数据?_Google Apps Script - Fatal编程技术网

Google apps script 有没有办法让appscript使用一个人拥有的电子表格作为另一个用户查找数据?

Google apps script 有没有办法让appscript使用一个人拥有的电子表格作为另一个用户查找数据?,google-apps-script,Google Apps Script,这是我目前的代码: function doGet() { var app = UiApp.createApplication().setTitle('When Am I Eligible?'); var panel = app.createVerticalPanel().setHeight("400px").setWidth("400px"); //var submitButton = app.createButton('Check'); var key= '???' var ss = S

这是我目前的代码:

function doGet() { 
var app = UiApp.createApplication().setTitle('When Am I Eligible?');
var panel = app.createVerticalPanel().setHeight("400px").setWidth("400px");
//var submitButton = app.createButton('Check');


var key= '???'
var ss = SpreadsheetApp.openById(key);
  var sh = ss.getSheetByName('SHEET');
  var last=ss.getLastRow();
  var data=sh.getRange(1,1,last,2).getValues();
  var valB= Session.getEffectiveUser();
  for(nn=0;nn<data.length;++nn){
    if (data[nn][1]==valB){
      var final = data[nn][0]
      break} ;// if a match in column B is found, break the loop
      }
// var finish = data[nn][0];
 var app = UiApp.getActiveApplication();
 //var statusLabel = app.createLabel().setVisible(true).setText(String.valueOf(finish))
 var answer = app.createLabel("BRO").setVisible(true).setText(final)
 panel.add(answer);
 app.add(panel);
  return app;
}
函数doGet(){
var app=UiApp.createApplication().setTitle('我什么时候有资格?');
var panel=app.createVerticalPanel().setHeight(“400px”).setWidth(“400px”);
//var submitButton=app.createButton('Check');
变量键='???'
var ss=电子表格应用程序openById(键);
var sh=ss.getSheetByName('SHEET');
var last=ss.getLastRow();
var data=sh.getRange(1,1,last,2).getValues();
var valB=Session.getEffectiveUser();

对于(nn=0;nn而言,简短的答案是否定的

一种可能的解决方法是将数据存储在链接到脚本的scriptdB中,从而继承应用程序的访问权限

该数据库应填充源电子表格中的数据,并在每次修改电子表格时重新同步(该过程可通过电子表格中的某些触发器自动完成)

当然,这将意味着在脚本中进行一些深层次的更改,但为保证数据隐私而付出的代价是值得的

作为一个非常简单的示例,这里有一个小代码,用于从具有2列的SS获取数据:

function getlistFromSS(){
  var ss = SpreadsheetApp.getActiveSpreadsheet()
  var sh = ss.getSheets()[0];
  var last =  ss.setActiveSheet(ss.getSheets()[0]).getLastRow();
  var list = sh.getRange(1,1,last,2).getValues(); 
  var key = [] ; var value = []
  deleteDb()
    for(cc=0;cc<list.length;++cc){
      key.push(list[cc][0]);
      value.push(list[cc][1]);
      }
    for(cc=0;cc<key.length;++cc){
      var db = ScriptDb.getMyDb()
      db.save({name:key[cc], url:value[cc]})    
        Logger.log(key[cc]+'   '+value[cc])
      }
    }
函数getlistFromSS(){ var ss=SpreadsheetApp.getActiveSpreadsheet() var sh=ss.getSheets()[0]; var last=ss.setActiveSheet(ss.getSheets()[0]).getLastRow(); var list=sh.getRange(1,1,last,2).getValues(); 变量键=[];变量值=[] deleteDb()
对于(cc=0;cc),在这种情况下,可以通过编写两个脚本来解决问题

脚本1: 这是在您访问电子表格时运行的脚本

function doGet(e){
  var key= '0Anzdf0g-SCsDdDF1WEVrYjZyclIzMkdmZjVYUTdXN2c'
  var ss = SpreadsheetApp.openById(key);
  var sh = ss.getSheetByName('SHEET');
  var last=ss.getLastRow();
  var data=sh.getRange(1,1,last,2).getValues();

  var valB = e.parameter.user; //Read it from e.

  for(nn=0;nn<data.length;++nn){
    if (data[nn][1]==valB){
      var final = data[nn][0]
      break} ;// if a match in column B is found, break the loop
      }
  return ContentService.createTextOutput(final);
}

我相信我已经修复了它,当我将电子表格的共享设置设置给域内有链接的任何人时,它看起来是正确的,那些在域内访问页面的人看到脚本正确运行,而没有将其添加到他们的驱动器中。谢谢你的帮助。

我相信我已经修复了它,当我设置spreadshee的共享设置时,它看起来是正确的t对于域内有链接的任何人,域内访问页面的人可以看到脚本在未将其添加到驱动器的情况下正确运行。不过,感谢您的帮助。=)可悲的是,这是一种幻觉……聪明的用户可以很容易地找到电子表格的url:-/这是真的,但有了我的用户,我敢打赌那些遭受设备嫉妒的人不会是那些试图找出别人有什么或有能力这样做的人。此外,它嵌入到谷歌网站中,因此通过让我t作为小工具发布到该站点。
function doGet() { 
var app = UiApp.createApplication().setTitle('When Am I Eligible?');
var panel = app.createVerticalPanel().setHeight("400px").setWidth("400px");
//var submitButton = app.createButton('Check');

var final = UrlFetchApp.fetch('URL OF SCRIPT 1 PUBLISHED AS A SERVICE');
// var finish = data[nn][0];
 var app = UiApp.getActiveApplication();
 //var statusLabel = app.createLabel().setVisible(true).setText(String.valueOf(finish))
 var answer = app.createLabel("BRO").setVisible(true).setText(final)
 panel.add(answer);
 app.add(panel);
  return app;
}