Reputation: 845
I want to create a dropdown in the google sheets sidebar that will include the name all sheets that do NOT contain 'Lookup' in their name.
I'm trying to use scriptlets to filter the sheet names and this is what I got in the Page.html file:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<!-- Select an exisiting data table -->
Select sheet to classify: <br>
<select id="dataSheetDropdown">
<? var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets() ?>
<? for(var i=0;i<sheets.length;i++) { ?>
<? sheet = sheets[i] ?>
<? if(sheet.indexOf("Lookup")>-1){?>
<option> <?= sheet.getName()?> </option>
<? } ?>
<? } ?>
</select>
<button onclick="selectLookup()">Select</button>
<script>
function selectLookup(){
var name=document.getElementsById("sheetDropdown")[0].value;
google.script.run.goToSheet(name);
};
</script>
</body>
</html>
When I try and run this script, I get this error:
TypeError: sheet.indexOf is not a function
Any idea how I can get my script to run correctly? Your help would be greatly appreciated
Upvotes: 1
Views: 466
Reputation: 201603
I believe your goal as follows.
Lookup
and show them to the dropdown list.sheet
is the sheet object. By this, such error occurs at indexOf
.Lookup
, please use if(sheet.getSheetName().indexOf("Lookup") == -1){
.When your script is modified, it becomes as follows.
<? sheet = sheets[i] ?>
<? if(sheet.indexOf("Lookup")>-1){?>
<option> <?= sheet.getName()?> </option>
<? } ?>
To:
<? sheet = sheets[i] ?>
<? if(sheet.getSheetName().indexOf("Lookup") == -1){?>
<option> <?= sheet.getSheetName() ?> </option>
<? } ?>
Upvotes: 2