繁体   English   中英

如何实现查询功能以将Google电子表格用作数据库?

[英]How to implement query function to use Google spreadsheet as a database?

我正在尝试使用电子表格作为数据库,其中每张纸都是一张桌子,而一个人的名字用作主键(这似乎不是最好的解决方案,但是良好的电子表格界面使我更喜欢这种方式解决方案,而不是尝试使用ScriptDB。)我想执行以下操作:当您在工作表上选择一个名称并按我添加的菜单上的按钮时,一个函数将在另一个表和屏幕中执行搜索,并显示所有该查询在另一个表中的结果,显示仅该表包含的属性记录(后来我想增加从GDocs模板生成文本文件的可能性)。 我的问题是:1)考虑到此屏幕/面板UI的长度是可变的(因为记录数在其他表格中可能有所不同),在Google Apps脚本中创建此面板/ UI的最佳方法是什么? (我不想使用Logger.log,因为我想添加一个将查询转换为文件的按钮)

2)除了此解决方案之外(在生成的2D数组中进行搜索):

function test(){ // to test the find function with an argument, 'any' in this case 
  var result = findItem('any');
  if(result){Logger.log(result.getA1Notation())}else{Logger.log('no luck !')};
}

function findItem(item){
  var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var data = ss.getDataRange().getValues()
  for(var n = 0;n<data.length;++n){
    if(data[n].indexOf(item)>-1){ // this is a "strict" find, ie the value must be the entire search item. If you want to do partial match you should compare differently...
      return (ss.getRange(n+1,data[n].indexOf(item)+1)); // if found return the range. note the +1 because sheets have 1 index while arrays have 0 index
    }
  }
  return false;// if we come to the end of sheet without result...
}

有另一种方法可以执行这样的查询吗?

谢谢你的帮助!

创建一个UI实例。 然后,在主面板内使用可滚动面板是执行此操作的最佳方法,然后使用数组搜索数据。 我通常创建页眉主体和页脚面板,使主体可滚动

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM