Home > Software engineering >  Formatting cells (to type Duration) with the Google Sheets API (v4)
Formatting cells (to type Duration) with the Google Sheets API (v4)

Time:11-18

I'm using the Google Sheets API (v4) to create/update spreadsheets programmatically and have run into the following issue:

I have seen via the JavaDoc that to set the cell to a NumberFormat of say, CURRENCY, I can set the NumberFormat type and pattern to:

"cell": {
  "userEnteredFormat": {
    "numberFormat": {
      "type": "CURRENCY",
      "pattern": "[$¥-411]#,##0.00"  // <--- Added
    }
  }
},
"fields": "userEnteredFormat.numberFormat"  // or "fields": "userEnteredFormat"

However, I do not see an option to set the NumberFormat type to DURATION. The acceptable enums I have found include: NUMBER_FORMAT_TYPE_UNSPECIFIED, TEXT, NUMBER, PERCENT, CURRENCY, DATE, TIME, DATE_TIME, SCIENTIFIC. Is there any way to set a cell format to a type Duration mimicking what you can do via UI?

enter image description here

After:

enter image description here

Reference:

  • Related