I
I
Igor2018-06-13 17:46:45
Node.js
Igor, 2018-06-13 17:46:45

I am using Nodejs. How can I change cell fill color or cell color in google spreadsheets?

sheets.spreadsheets.values.append({
auth: auth,
spreadsheetId: sId,
range: 'list1!R'+realy+'C'+cCount,
valueInputOption: "RAW",
resource:{values: } // - Writing data to the cell
},
(err, response) => {if (err) return console.log(err)}
);
Is it possible to pass the background color of the cell along with the data via spreadsheets.values.append?
We also know that you can get the background color like this:
function data(auth) {
const sheets = google.sheets({version: 'v4', auth});
const params = {
spreadsheetId:'
fields:"sheets"
};
sheets.spreadsheets.get(params,
(err, {data}) => {
if (err) return console.log('The API returned an error: ' + err);
console.log("Value in cell: ", data.sheets[0].data[0].rowData[0].values[2].formattedValue);
console.log("Background Color: ",data.sheets[0].data[0].rowData[0 ].values[2].effectiveFormat.backgroundColor);
//rowData[х] - Row on the sheet
//values[х] - Column
// The value in the cell must not be empty.
})
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor, 2018-06-15
@aif88

Implemented through conditional formatting, maybe it will help someone:
function data(auth) {
const sheets = google.sheets({version: 'v4', auth});
var myRange = {
sheetId: 0,
startRowIndex: 1,
endRowIndex: 2,
startColumnIndex: 1,
endColumnIndex: 2
};
var requests = [{
addConditionalFormatRule: {
rule: {
ranges: [ myRange ],
booleanRule: {
condition: {
type: 'NOT_BLANK'
},
format: {
backgroundColor: { red: 1, green: 0.1, blue: 0.1 }
}
}
},
index: 0
}
}];
var body = {
requests
};
var sId='mySpreadsheetID';
sheets.spreadsheets.batchUpdate(
{
spreadsheetId: sId,
resource: body
}, function(err, response) {
if(err) {
// Handle error.
console.log(err);
}
});
}
If someone knows how to make it easier on node - please - let me know.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question