こちらのソースコードでフィルタが操作できました。
https://sites.google.com/site/scriptsexamples/learn-by-example/google-sheets-api/filters
「ReferenceError: 「Sheets」が定義されていません。」というエラーになったのですが、
https://developers.google.com/apps-script/advanced/sheets
の「This is an advanced service that must be enabled before use.」のリンクをクリックし、
下記の操作でセットアップできました。
Google SpreadSheetの[ツール]>[スクリプト エディタ]でスクリプトエディタを立ち上げ、
Google Script Editorの[リソース]>[Googleの拡張サービス]から
[Google Sheets API]を[ON(有効)]にし、
さらに、[Google API コンソール]というリンク
から「Google Sheets API」を検索し、有効にしました。
Enabling advanced services
To use an advanced Google service, follow these instructions:
In the script editor, select Resources > Advanced Google services....
In the dialog that appears, click the on/off switch next to the service you want to use.
At the bottom of the dialog, click the link for the Google API Console.
In the console, click into the filter box and type part of the name of the API (for example, "Calendar"), then click the name once you see it.
On the next screen, click Enable API.
Close the API Console and return to the script editor. Click OK in the dialog. The advanced service you enabled is now available in autocomplete.
(参考)https://teratail.com/questions/107380
エラーが出なくなり、コードを実行できるようになったのですが、
なかなかうまくフィルタが設定されなかったのですが、
「var columnIndex = 2;」の部分がフィルタに設定したい列の指定でした。
0にすると1列目のフィルタセット、1にすると2列目のフィルタセット、・・・
というようになりました。
最後までお読みいただき、ありがとうございます。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。