Hide Rows in a Google Spreadsheet based on first Character in a cell -
i working on adding functionality google spreadsheet. spreadsheet imports data web, , have formatted nicely. 1 of columns series of strings, formatted in 1 of 2 ways - string or *string * without space (basically importing italics web).
i trying come script runs when open spreadsheet, will:
- unhide rows in spreadsheet
- loop through spreadsheet
- hide every row column 2(b) begins asterisk
i have following:
function onopen() { var ss = spreadsheetapp.getactivespreadsheet(); var sheet = ss.getsheetbyname("dodh"); sheet.showrows(1, sheet.getmaxrows()); for(var i=1; i<sheet.getmaxrows()+1; ++i){ if (sheet.getrange(i, 2).getvalue().){ sheet.hiderow(i) } } }
i don't know how access string inside each cell, , how access characters within string. thank in advance help.
here updated code. see comments have na insight
function onopen() { var ss = spreadsheetapp.getactivespreadsheet(); var sheet = ss.getsheetbyname("dodh"); var maxrows = sheet.getmaxrows(); //show rows sheet.showrows(1, maxrows); //get data clumn b var data = sheet.getrange('b:b').getvalues(); //iterate on rows for(var i=0; i< data.length; i++){ //compare first character, if asterisk, hide row if(data[i][0].charat(0) == '*'){ sheet.hiderows(i+1); } } }