質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Google Apps Script

Google Apps ScriptはGoogleの製品と第三者のサービスでタスクを自動化するためのJavaScriptのクラウドのスクリプト言語です。

Q&A

解決済

1回答

678閲覧

Google Apps Scriptでの、Googleスプレッドシートのフィルタの操作

yoichi0702

総合スコア19

Google Apps Script

Google Apps ScriptはGoogleの製品と第三者のサービスでタスクを自動化するためのJavaScriptのクラウドのスクリプト言語です。

0グッド

0クリップ

投稿2018/01/03 01:44

編集2018/01/03 02:36

Google Apps Scriptで、Googleスプレッドシートのフィルタを操作したく、試行錯誤していたのですが、それらしい情報として、
https://sites.google.com/site/scriptsexamples/learn-by-example/google-sheets-api/filters
を見つけました。

実行してみたところ、
「ReferenceError: 「Sheets」が定義されていません。」
と表示されてしまい、実行できませんでした。

いろいろ調べたのですが、どうやったら先に進めるかわかりません。
どうしたら先に進めるのか教えていただけないでしょうか?

Google

1function setFilter() { 2 var ss = SpreadsheetApp.getActiveSpreadsheet(); 3 4 var filterSettings = {}; 5 6 // The range of data on which you want to apply the filter. 7 // optional arguments: startRowIndex, startColumnIndex, endRowIndex, endColumnIndex 8 filterSettings.range = { 9 sheetId: ss.getActiveSheet().getSheetId() 10 }; 11 12 // Criteria for showing/hiding rows in a filter 13 // https://developers.google.com/sheets/api/reference/rest/v4/FilterCriteria 14 filterSettings.criteria = {}; 15 var columnIndex = 2; 16 filterSettings['criteria'][columnIndex] = { 17 'hiddenValues': ["England", "France"] 18 }; 19 20 var request = { 21 "setBasicFilter": { 22 "filter": filterSettings 23 } 24 }; 25 Sheets.Spreadsheets.batchUpdate({'requests': [request]}, ss.getId()); 26}

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

※質問と回答の時間差がありませんが、昨日、苦戦して、質問しようと思ったのですが、今朝、再格闘して、解決策を見出すことができました。
私と同じように迷う方がいらっしゃるかもしれませんので、情報共有の意味で、解決策を共有させていただきます。
ありがとうございます。

https://developers-jp.googleblog.com/2017/05/using-google-sheets-filters-in-add-ons.html
より
「Sheets API」や「Advanced Sheets Service」というのを使うと、フィルタが操作できるらしいことがわかりました。

https://developers.google.com/apps-script/advanced/sheets
より
「This is an advanced service that must be enabled before use.」
のリンクをクリックすると、
https://developers.google.com/apps-script/guides/services/advanced

に飛び、下記の操作で、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.

投稿2018/01/03 01:49

yoichi0702

総合スコア19

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問