【问题标题】:Filtering Information from a google sheet back to a webapp将信息从 google sheet 过滤回 webapp
【发布时间】:2020-09-01 10:36:58
【问题描述】:

我正在 Google Scripts 中创建一个网络应用程序,以将信息插入到我的电子表格数据库中。但是,如果该项目已经在我的电子表格中,它将返回一些信息,让我知道它已经被添加。我已经能够让它工作,将两列信息返回到我的 web 应用程序。我的问题是,它的代码似乎太多了。我想看看是否有办法让它变得紧凑。我尝试使用数组、过滤器和 for 循环,但无法正常工作。 我正在学习javascript,因为我这样做。

对此的任何见解将不胜感激。

function getSSinfo(studentid){
  var ss = SpreadsheetApp.openByUrl(url);
  var ws = ss.getSheetByName("SSDatabse");
  var data = ws.getRange(1, 1, ws.getLastRow(),10).getValues();

  var ssNameList = data.map(function(r){ return r[0];});

  var ssGroupList = data.map(function(r){ return r[7];});
  var position = ssNameList.indexOf(studentid);

    if(position > -1){
         return ssGroupList[position];
    } else {
     return 'no found';
  }
}


 function getSSinfo1(studentid){
  var ss = SpreadsheetApp.openByUrl(url);
  var ws = ss.getSheetByName("SSDatabse");
  var data = ws.getRange(1, 1, ws.getLastRow(),10).getValues();

  var ssNameList = data.map(function(r){ return r[0];});

  var ssGroupList = data.map(function(r){ return r[9];});
  var position = ssNameList.indexOf(studentid);
    if(position > -1){
         return ssGroupList[position];
    } else {
     return 'no found';
  }
}

 function getInfo(){
       var studentname = document.getElementById("sid").value.trim();
         if (studentname.length >= 2){
            
            var gscript = {}
              gscript.usi = google.script.run.withSuccessHandler(updateSSinfo).getSSinfo(studentname);
              gscript.usi1 = google.script.run.withSuccessHandler(updateSSinfo1).getSSinfo1(studentname);
              google.script.run.withSuccessHandler(updateSSinfo1).getSSinfo1(studentname);
              google.script.run.withSuccessHandler(updateSSinfo).getSSinfo(studentname);
        }
    }
   
    
 function updateSSinfo(ssinfo){
         document.getElementById("emailInfo").value = ssinfo;
  }
   
 function updateSSinfo1(sinfo){
         document.getElementById("test").value = sinfo;  
}

【问题讨论】:

    标签: javascript html arrays google-sheets web-applications


    【解决方案1】:

    在研究了您的问题后,我了解到您正在使用表格作为数据库。如果是这种情况,将电子表格用作数据库并不是一个好主意。我强烈建议改用 SQL 数据库,例如 Google Cloud SQL、MySQL、Microsoft SQL Server 或 Oracle 数据库。您可以使用JDBC service 将这些数据库与您的代码连接起来。

    此外,我积极提倡使用batch methods 而不是SpreadsheetApp 来进一步优化数据传输。您可以阅读有关批处理操作的更多信息here。请向我提出任何疑问,以便我可以进一步帮助您。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-22
      • 1970-01-01
      • 2021-09-20
      • 1970-01-01
      • 1970-01-01
      • 2012-07-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多