如何将数据过滤器添加到我的Google工作表标题中

时间:2017-04-18 15:28:59

标签: python google-sheets-api

我想在google工作表的标题中添加一个过滤器。我发现THIS ANSWER使用C#并尝试从中构建JSON。这是我想出的但没有运气:

Reset-Profile -Username TestUsername -Server Localhost -WhatIf -Verbose

任何人都知道我错了什么?

1 个答案:

答案 0 :(得分:3)

来自Google Sheets API documentation

Public Function SendEmail(strRecipients As String, strSubject As String, _
       Optional strBody As String, Optional strFilePath As String, _
       Optional strFileExtension As String) As String

    On Error GoTo ProcError

    Dim myObject As Object
    Dim myItem As Object
    Dim strFullPath As String
    Dim strFileName As String
    Dim strAttachPath As Variant
    Dim intAttachments As Integer

    Set myObject = CreateObject("Outlook.Application")
    Set myItem = myObject.CreateItem(0)

    With myItem
        .Subject = strSubject
        .To = strRecipients

        If Len(Trim(strBody)) > 0 Then
            .body = strBody
        End If

        If Len(Trim(strFileExtension)) = 0 Then
            strFileExtension = "*.*"
        End If

        If Len(strFilePath) > 0 Then
            strFullPath = strFilePath & "\" & strFileExtension

            If Len(Trim(strFullPath)) > 0 Then  'An optional path was included
                strFileName = Dir(strFullPath)
                Do Until strFileName = ""
                    intAttachments = intAttachments + 1
                    strAttachPath = (strFilePath & "\" & strFileName)
                    .Attachments.add (strAttachPath)
                    ' Debug.Print strAttachPath
                    strFileName = Dir()
                Loop
            End If
        End If

        .Send
        SendEmail = "Message placed in outbox with " & intAttachments & " file attachment(s)."
    End With

ExitProc:
    Set myItem = Nothing
    Set myObject = Nothing
    Exit Function
ProcError:
    MsgBox "Error " & Err.Number & ": " & Err.Description, _
               vbCritical, "Error in SendMail Function..."
    SendEmail = "A problem was encountered attempting to automate Outlook."
    Resume ExitProc

End Function

我自己没有尝试使用过滤器,但似乎不需要按键"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. }, }, }, }, } AddFilterViewRequestAddFilterViewRequest