Как я могу добавить фильтр к моему запросу в Google Sheets API? - PullRequest
0 голосов
/ 02 июля 2019

Я хотел бы получить 1 строку из моего листа Google по указанным критериям. В данном случае это строковое значение ячейки. Я обнаружил, что могу использовать FilterView для этого, но не могу его добавить.

Вот что у меня сейчас

private static void getFilteredView(String searchValue) throws IOException {
        Map<String, FilterCriteria> stringCriteriaMap = new TreeMap<>();
        FilterCriteria filterCriteria = new FilterCriteria();
        filterCriteria.setCondition(new BooleanCondition()
                .setType("TEXT_EQ")
                .setValues(Collections.singletonList(
                        new ConditionValue().setUserEnteredValue(searchValue)
                ))
        );
        stringCriteriaMap.put("Text equals", filterCriteria);
        FilterView filterView = new FilterView().setCriteria(stringCriteriaMap);
        Request r = new Request();
        r.getAddFilterView().setFilter(filterView);
        AddFilterViewRequest body = new AddFilterViewRequest().setFilter(filterView);
        Sheets.Spreadsheets.Values.BatchUpdate request = getSheetService().spreadsheets().values()
                .batchUpdate(spreadsheetId, body).execute();

    }

проблема в том, что здесь

.batchUpdate(spreadsheetId, body).execute();

это не позволяет мне передать свой аргумент (тело) методу, оно говорит:

batchUpdate (String, com.google.api.services.sheets.v4.model.BatchUpdateValuesRequest)
in Values cannot be applied to (String, com.google.api.services.sheets.v4.model.AddFilterViewRequest)

К сожалению, API предоставил примеры на Python, и я не могу понять, как это решить. Вот примеры из API: https://developers.google.com/sheets/api/guides/filters

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...