I am attempting to automatically apply new formatting to my spreadsheet, however while it does not appear to cause any errors, it is not working.
My goal is to apply duration formatting to columns G and H (index 6 and 7) of my spreadsheet. I am automatically updating the spreadsheet with string data in the format without brackets:
[D]:[H]:[M]
Where D, H, and M may be single or double digit. I would like it to display in the following format without brackets on the spreadsheet:
[hh]:[mm]:[ss]
Where there is always at least two digits in each column. However, the spreadsheet seems to automatically choose formatting regardless of what formatting I request, and it chooses a decimal number format. How can I use the batchUpdate() function to apply a working duration formatting to just these two columns?
My Code attempt is below. I am using the Node.js Google API Client Library.
sheets.spreadsheets.batchUpdate({
spreadsheetId: '1AakOf_W90JdAtL0R8XeMmacWrnBx8wLKrMCdHdnNmhM',
resource: {
requests: [{
updateCells:{
range: {
startColumnIndex: 6,
endColumnIndex: 8
},
'fields': 'userEnteredFormat/numberFormat(pattern,type),effectiveFormat/numberFormat(pattern,type)',
rows:[{
values:[{
userEnteredFormat:{
numberFormat:{
pattern: '[hh]:[mm]:[ss]',
type: 'TIME'
}
},
effectiveFormat:{
numberFormat:{
pattern: '[hh]:[mm]:[ss]',
type: 'TIME'
}
}
}]
}]
}
}
]
}
}, function(err, response, responseBody){
if(err){
console.log(err);
console.log(err.code);
}
});
It would seem that the issue lies within the indexing of columns on the spreadsheet. When writing this code, I assumed that the columns were indexed starting at zero. However, it would appear that the indexing starts at -1, as columns G and H are actually represented by indices 5 and 6.