简体   繁体   English

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

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

I'm trying to use a spreadsheet as a database, where each sheet would be a table and the name of a person is used as a primary key (It seems not to be the best solution, but the good spreadsheet interface makes me prefer this solution rather than trying to use ScriptDB.) And I want to do the following: When you select a name on a sheet and press a button on the menu I added, a function performs a search in another table and a screen and shows all the results of that query in the other table, showing properties records that only that table contains (later I want to add the possibility to generate a text file from a GDocs template). 我正在尝试使用电子表格作为数据库,其中每张纸都是一张桌子,而一个人的名字用作主键(这似乎不是最好的解决方案,但是良好的电子表格界面使我更喜欢这种方式解决方案,而不是尝试使用ScriptDB。)我想执行以下操作:当您在工作表上选择一个名称并按我添加的菜单上的按钮时,一个函数将在另一个表和屏幕中执行搜索,并显示所有该查询在另一个表中的结果,显示仅该表包含的属性记录(后来我想增加从GDocs模板生成文本文件的可能性)。 My questions is: 1) Considering this screen/panel UI has a variable length (because the record number may vary in other tables), what is the best way to create this panel/UI in Google Apps Script? 我的问题是:1)考虑到此屏幕/面板UI的长度是可变的(因为记录数在其他表格中可能有所不同),在Google Apps脚本中创建此面板/ UI的最佳方法是什么? (I don't want to use the Logger.log because I want to add a button to convert the query into a file) (我不想使用Logger.log,因为我想添加一个将查询转换为文件的按钮)

2) In addition to this solution (a search in the resulting 2D array): 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...
}

There is an alternative method to perform queries like this? 有另一种方法可以执行这样的查询吗?

THANKS for any help! 谢谢你的帮助!

Create a UI instance. 创建一个UI实例。 Then a scrollable panel inside a main panel is the best way of doing this and then using array's to search through the data. 然后,在主面板内使用可滚动面板是执行此操作的最佳方法,然后使用数组搜索数据。 I typically create header body and footer panels with the body being scrollable 我通常创建页眉主体和页脚面板,使主体可滚动

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

相关问题 Google Apps脚本:如何使用电子表格中的数据查询外部数据库? - Google Apps Script: how to use data in a spreadsheet to query a external database? 如何在博客中使用谷歌电子表格作为登录数据库? - how to use google spreadsheet as login database in blogger? 如何将Google电子表格用作实时操作的数据库 - how can I use google spreadsheet as a database for real time ops Google电子表格查询query.send回调函数返回值 - Google spreadsheet query query.send callback function return value 如何在谷歌电子表格中使用 updateDimensionProperties - How exactly to use updateDimensionProperties in google-spreadsheet 如何优化 Google Spreadsheet function 执行时间? - How to optimize Google Spreadsheet function execution time? OnEdit function 与谷歌电子表格 - OnEdit function with google Spreadsheet 如何使用Google可视化API检索Google电子表格单元格值? - How to use Google visualization API to retrieve google spreadsheet cell value? 在谷歌电子表格中查询当前月份 - QUERY current month in google spreadsheet 如何在谷歌电子表格上使用 IMPORTXML 来获取股票的上市前价值? - How to use IMPORTXML on Google Spreadsheet to get premarket value for a stock?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM