Google Script to see if text contains a value

前端 未结 4 1194
既然无缘
既然无缘 2021-02-06 22:25

I have a google form that when the user submits it will trigger my function to run which is creating a summary of what they submitted as a Google Doc. I know it can automaticall

4条回答
  •  野的像风
    2021-02-06 22:37

    I had to add a .toString to the item in the values array. Without it, it would only match if the entire cell body matched the searchTerm.

    function foo() {
        var ss = SpreadsheetApp.getActiveSpreadsheet();
        var s = ss.getSheetByName('spreadsheet-name');
        var r = s.getRange('A:A');
        var v = r.getValues();
        var searchTerm = 'needle';
        for(var i=v.length-1;i>=0;i--) {
            if(v[0,i].toString().indexOf(searchTerm) > -1) {
                // do something
            }
        }
    };
    

提交回复
热议问题