2017-04-18 39 views
4

我想在我的谷歌表格的標題中添加一個過濾器。我發現使用C#的代碼爲THIS ANSWER,並試圖從中構建JSON。這是我想出的,但沒有運氣:如何將數據過濾器添加到我的谷歌表格標題

{'AddFilterViewRequest' : { 
     'AddFilterViewResponse': { 
     'Filter' : { 
        'FilterView': { 
        'title' : "Hide rows with errors", 
        'range': {'sheetId': sheet_id, 
          'startRowIndex': 0, 
          'endRowIndex': 2, 
          'startColumnIndex': 1, 
          'endColumnIndex': 31} 
        } 
     } 
     } 
}} 

任何人都知道我要去哪裏錯了?

+2

這可能會問很多,但可以添加一些代碼,使我們能夠[看/驗證](https://stackoverflow.com/help/mcve)如何使用這個JSON對象? – spacepickle

+0

我想在我的excel標題中添加一個簡單的過濾器,以便用戶能夠過濾可能的值。上面的代碼是我唯一擁有的,對不起。 – mongotop

+1

也許我不打算這麼做,因爲對於那些有豐富的google sheet api知識的人來說,這可能是顯而易見的,但是你可以展示一些python代碼,它如何與表單交互,應該發生什麼以及實際發生什麼?這可以讓我更容易理解可能出現的問題 – spacepickle

回答

3

Google Sheets API documentation

"addFilterView": { # Adds a filter view. # Adds a filter view. 
     "filter": { # A filter view. # The filter to add. The filterViewId 
      # field is optional; if one is not set, an id will be randomly generated. (It 
      # is an error to specify the ID of a filter that already exists.) 
     "title": "A String", # The name of the filter view. 
     "namedRangeId": "A String", # The named range this filter view is backed by, if any. 
      # 
      # When writing, only one of range or named_range_id 
      # may be set. 
     "filterViewId": 42, # The ID of the filter view. 
     "range": { # A range on a sheet. # The range this filter view covers. 
      # 
      # When writing, only one of range or named_range_id 
      # may be set. 
      # All indexes are zero-based. 
      # Indexes are half open, e.g the start index is inclusive 
      # and the end index is exclusive -- [start_index, end_index). 
      # Missing indexes indicate the range is unbounded on that side. 
      # 
      # For example, if `"Sheet1"` is sheet ID 0, then: 
      # 
      # `Sheet1!A1:A1 == sheet_id: 0, 
      #     start_row_index: 0, end_row_index: 1, 
      #     start_column_index: 0, end_column_index: 1` 
      # 
      # `Sheet1!A3:B4 == sheet_id: 0, 
      #     start_row_index: 2, end_row_index: 4, 
      #     start_column_index: 0, end_column_index: 2` 
      # 
      # `Sheet1!A:B == sheet_id: 0, 
      #     start_column_index: 0, end_column_index: 2` 
      # 
      # `Sheet1!A5:B == sheet_id: 0, 
      #     start_row_index: 4, 
      #     start_column_index: 0, end_column_index: 2` 
      # 
      # `Sheet1 == sheet_id:0` 
      # 
      # The start index must always be less than or equal to the end index. 
      # If the start index equals the end index, then the range is empty. 
      # Empty ranges are typically not meaningful and are usually rendered in the 
      # UI as `#REF!`. 
      "endRowIndex": 42, # The end row (exclusive) of the range, or not set if unbounded. 
      "endColumnIndex": 42, # The end column (exclusive) of the range, or not set if unbounded. 
      "sheetId": 42, # The sheet this range is on. 
      "startColumnIndex": 42, # The start column (inclusive) of the range, or not set if unbounded. 
      "startRowIndex": 42, # The start row (inclusive) of the range, or not set if unbounded. 
     }, 
     "sortSpecs": [ # The sort order per column. Later specifications are used when values 
      # are equal in the earlier specifications. 
      { # A sort order associated with a specific column or row. 
      "sortOrder": "A String", # The order data should be sorted. 
      "dimensionIndex": 42, # The dimension the sort should be applied to. 
      }, 
     ], 
     "criteria": { # The criteria for showing/hiding values per column. 
      # The map's key is the column index, and the value is the criteria for 
      # that column. 
      "a_key": { # Criteria for showing/hiding rows in a filter or filter view. 
      "hiddenValues": [ # Values that should be hidden. 
       "A String", 
      ], 
      "condition": { # A condition that can evaluate to true or false. # A condition that must be true for values to be shown. 
       # (This does not override hiddenValues -- if a value is listed there, 
       # it will still be hidden.) 
       # BooleanConditions are used by conditional formatting, 
       # data validation, and the criteria in filters. 
       "values": [ # The values of the condition. The number of supported values depends 
        # on the condition type. Some support zero values, 
        # others one or two values, 
        # and ConditionType.ONE_OF_LIST supports an arbitrary number of values. 
       { # The value of the condition. 
        "relativeDate": "A String", # A relative date (based on the current date). 
         # Valid only if the type is 
         # DATE_BEFORE, 
         # DATE_AFTER, 
         # DATE_ON_OR_BEFORE or 
         # DATE_ON_OR_AFTER. 
         # 
         # Relative dates are not supported in data validation. 
         # They are supported only in conditional formatting and 
         # conditional filters. 
        "userEnteredValue": "A String", # A value the condition is based on. 
         # The value will be parsed as if the user typed into a cell. 
         # Formulas are supported (and must begin with an `=`). 
       }, 
       ], 
       "type": "A String", # The type of condition. 
      }, 
      }, 
     }, 
     }, 
    } 

我還沒有使用過濾器自己嘗試,但它似乎是不需要AddFilterViewRequestAddFilterViewRequestFilter鑰匙。

+0

有人可以通過樣本數據顯示一個正在填充的條件部分的例子嗎?我不確定所有我不知道的內容,但我認爲第一步是弄清楚列號索引的位置。 – donL

+0

謝謝你的例子。你知道如何將該過濾器視圖應用於工作表嗎?因爲現在它只創建一個視圖,您可以在「從數據篩選器視圖」下拉列表中看到該視圖。 – mongotop

相關問題