Reputation: 2637
I'm trying to change the color of cells/text color/borders in a google sheet using Node.js. I have some data, and I want to put that data in the sheet and highlight certain rows based on conditions. The putting in data part works when I use sheets.spreadsheets.values.update
. As a basic test for highlighting, I tried just changing some attributes of cell A1 like this:
sheets.spreadsheets
.batchUpdate({
spreadsheetId: masterOrderSheetID,
resource: {
requests: [
{
updateCells: {
start: {
sheetId: 0,
rowIndex: 0,
columnIndex: 0,
},
fields: '*',
rows: [
{
values: [
{
effectiveValue: {
stringValue: 'hello please',
},
effectiveFormat: {
backgroundColor: {
red: 1,
green: 0,
blue: 0,
alpha: 0.5,
},
backgroundColorStyle: {
rgbColor: {
red: 1,
green: 0,
blue: 0,
alpha: 0.5,
},
},
textRotation: {
angle: 45,
},
},
},
],
},
],
},
},
],
includeSpreadsheetInResponse: true,
responseIncludeGridData: true,
},
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
but all that happens is that the formatting on cell A1 gets reset (I manually set it to bold, and it un-set the boldness). The value does not get set to 'hello please'
.
How do you set the color of a cell (or range of cells)?
Upvotes: 1
Views: 1444
Reputation: 201378
How about the following suggestions?
Modify fields
in your request body as follows:
fields: '*',
fields: 'effectiveValue,effectiveFormat',
Modify fields
, effectiveValue
and effectiveFormat
in your request body as follows. (effectiveValue
and effectiveFormat
are modified to userEnteredValue
and userEnteredFormat
, respectively.)
fields: '*',
rows: [
{
values: [
{
effectiveValue: {
stringValue: 'hello please',
},
effectiveFormat: {
fields: 'userEnteredValue,userEnteredFormat"',
rows: [
{
values: [
{
userEnteredValue: {
stringValue: 'hello please',
},
userEnteredFormat: {
Upvotes: 2