I'm using firebase cloud functions in order to add and edit data in an existing spreadsheet.
The first operation I do to the sheet is adding a first row that contains the columns names. After that I change the format of the first inserted row to be in bold. That succeeded but then, every row of data I append to the sheet appear bold as well.
Here is a snippet of my code:
header = [/* array of the columns names */];
await appendPromise({
spreadsheetId: spreadsheetID,
range: 'Sheet1',
valueInputOption: 'USER_ENTERED',
insertDataOption: 'INSERT_ROWS',
resource: {
values: [header],
},
});
return updateBatchPromise(spreadsheetID,
{"requests": [
{"repeatCell": {
"range": {
"sheetId": 0,
"startRowIndex": 0,
"endRowIndex": 1
},
"cell": {
"userEnteredFormat": {
"textFormat": {
"bold": true
}
}
},
"fields": "userEnteredFormat.textFormat.bold"
}}
]}
)
/*...... HELPER FUNCTIONS........*/
function appendPromise(requestWithoutAuth) {
return new Promise((resolve, reject) => {
google.auth.getClient({
scopes: ['https://www.googleapis.com/auth/spreadsheets'],
}).then((client) => {
const sheets = google.sheets('v4');
const request = requestWithoutAuth;
request.auth = client;
return sheets.spreadsheets.values.append(request, (err, response) => {
if (err) {
console.log(`The API returned an error: ${err}`);
return reject(err);
}
return resolve(response.data);
});
});
});
}
function updateBatchPromise(spreadsheetId, res) {
return new Promise((resolve, reject) => {
google.auth.getClient({
scopes: ['https://www.googleapis.com/auth/spreadsheets'],
}).then((client) => {
const sheets = google.sheets('v4');
return sheets.spreadsheets.batchUpdate({
auth: client,
spreadsheetId: spreadsheetId,
resource: res
}, (err, response) => {
if (err) {
console.log(`The API returned an error: ${err}`);
return reject(err);
}
return resolve(response.data);
});
});
});
}
The first picture is the requested behavior and the second is what I got.
