0

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

2)除此解决方案(在生成的二维数组中搜索):

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... 
} 

有一种替代方法来执行这样的查询吗?

感谢您的帮助!

回答

0

创建一个UI实例。然后在主面板内的可滚动面板是这样做的最好方法,然后使用数组来搜索数据。我通常创建标题主体和页脚面板,主体可滚动

相关问题