是否有脚本将查询和导入范围组合在一起

时间:2019-03-29 08:13:22

标签: google-apps-script google-sheets

需要一个脚本来执行查询和导入范围的功能。脚本应仅在提供条件的情况下导入特定的列和行。

function UpdateRange() { var values = SpreadsheetApp.openById('Source'). getSheetByName('Dump').getRange('A:Q').getValues(); SpreadsheetApp.getActive().getSheetByName('DATA'). getRange(1,1,values.length,values[0].length).setValues(values); //destination as getrange([row], [col] }

=Query(IMPORTRANGE("source sheet","A:AC"),"Select Col2,Col3,Col4,Col6,Col29,Col9,Col12,Col17,Col25 where Col4 contains date'"&TEXT(TODAY(),"yyyy-MM-dd")&"' and Col11 contains'' and Col17 contains 'cancelled' and Col7 contains 'City'",1)

需要执行代码中提到的公式的动作

1 个答案:

答案 0 :(得分:0)

使用AlaSQL的最简单方法

function importrangequery(){
  var alasql = AlaSQLGS.load();
  var data =  SpreadsheetApp
    .openById("14I34TM84uBnVILA3KQh9Y2LZr_Tr_fMsDQI2kYfht-E")
    .getSheets()[0]
    .getDataRange()
    .getValues()
    .slice(0, 1000);
  var res = alasql('\
SELECT MATRIX t.[0], t.[1] \
FROM ? as t \
WHERE t.[1] LIKE "%wq%" OR t.[1] LIKE "%uu%"',
                   [data]);
  Logger.log(res);

/* 
  // To insert into another table

  var output = SpreadsheetApp
    .openById("10uS4_YD4z2Ea-UnxkdydxB6QAKJ9GQUQX4Ozvw0F13o")
    .getSheetByName('Output');
  output.getDataRange().clearContent();
  output.getRange(1,1,res.length, res[0].length).setValues(res);
*/

}

lib https://github.com/oshliaer/alasqlgs

示例https://drive.google.com/drive/folders/1iG34CHDVBIwqG8yOcjJYHl3gx1IsTzOJ

https://stackoverflow.com/a/28751946/1393023

还有其他方法