2017-08-25 95 views
0

我試圖在列上設置日期格式,以便日期顯示如下:14-Aug-2017。這是我做的方式:我希望所有列E除了頭部細胞的細胞更新,因此範圍定義使用API​​和Python在Google表格中設置日期格式

requests = [ 
    { 
     'repeatCell': 
     { 
      'range': 
      { 
       'startRowIndex': 1, 
       'startColumnIndex': 4, 
       'endColumnIndex': 4 
      }, 
      'cell': 
      { 
       "userEnteredFormat": 
       { 
        "numberFormat": 
        { 
         "type": "DATE", 
         "pattern": "dd-mmm-yyyy" 
        } 
       } 
      }, 
      'fields': 'userEnteredFormat.numberFormat' 
     } 
    } 
] 
body = {"requests": requests} 
response = service.spreadsheets().batchUpdate(spreadsheetId=SHEET, body=body).execute() 

。我使用http://wescpy.blogspot.co.uk/2016/09/formatting-cells-in-google-sheets-with.htmlhttps://developers.google.com/sheets/api/samples/formatting作爲此方法的基礎。

但是,單元格不會使用該格式顯示其內容。他們仍然處於「自動」格式,要麼顯示我正在存儲的數字值(從1900年1月1日起的天數)或(有時)顯示日期。

將sheetId添加到範圍定義不會改變結果。

我沒有收到服務返回的錯誤,並且響應只包含spreadsheetId和一個空的答覆結構[{}]。

我得到什麼錯誤?

回答

0

我發現錯誤 - 在endColumnIndex需要是5,而不是4

我沒有讀到第一條鏈接不夠仔細!