我正在嘗試通過 NodeJS Google Sheets 庫在 C 列中設定單個特定單元格的背景。但是,我收到此錯誤
errors: [
{
message: `Invalid value at 'requests[0].update_cells.range' (type.googleapis.com/google.apps.sheets.v4.GridRange), "'Question of the day'!C2"`,
reason: 'invalid'
}
]
這是我的方法呼叫
sheets.spreadsheets.batchUpdate({
auth: this._token,
spreadsheetId: this._spreadsheet,
resource: {
requests: [{
updateCells: {
range: '\'Question of the day\'!C' (index 1),
fields: 'userEnteredFormat',
rows: [{
values: [{
userEnteredFormat: {
backgroundColor: {
red: 1,
green: 0,
blue: 0
}
}
}]
}]
}
}]
}
})
身份驗證和電子表格一樣正確。我在 Google 表格中測驗了錯誤引發的范圍,這是一個有效的作業范圍。
我不確定為什么會這樣
uj5u.com熱心網友回復:
在您的腳本中,使用了 batchUpdate 方法的 UpdateCellsRequest。在這種情況下,范圍是不是 A1Notation 的 gridRange。我認為這是您的問題的原因。
修改后的腳本:
在這種情況下,請使用“今日問題”表單的表單 ID gridRange。
const gridRange = {
"sheetId": 0, // Please set the sheet ID of the sheet of "Question of the day".
"startRowIndex": index,
"endRowIndex": index 1,
"startColumnIndex": 2, // This means the column "C"
"endColumnIndex": 3 // This means the column "C"
};
sheets.spreadsheets.batchUpdate({
auth: this._token,
spreadsheetId: this._spreadsheet,
resource: {
requests: [{
updateCells: {
range: gridRange,
fields: 'userEnteredFormat',
rows: [{
values: [{
userEnteredFormat: {
backgroundColor: {
red: 1,
green: 0,
blue: 0
}
}
}]
}]
}
}]
}
})
參考:
- 更新細胞請求
- 網格范圍
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/438821.html
