Google sheets API - add banding ("zebra coloring") from apps script -
i'm looking example code how add new banded range (addbanding request) google sheet. have tried modify of examples available in v4 api doc, keep getting "invalid json payload" errors.
code:
function addbanding() { var request = { 'addbanding': { 'bandedrangeid': 1, 'range': { 'sheetid': 0, 'startrowindex': 0, 'endrowindex': 15, 'startcolumnindex': 0, 'endcolumnindex': 4, }, 'rowproperties': { 'headercolor': { 'red': 1, 'green': 0, 'blue': 1, 'alpha': 1, }, 'firstbandcolor': { 'red': 1, 'green': 0, 'blue': 0, 'alpha': 0, }, 'secondbandcolor': { 'red': 0, 'green': 1, 'blue': 0, 'alpha': 0, } }, }, }; body = {'requests': request}; var spreadsheetid = spreadsheetapp.getactivespreadsheet().getid(); var response = sheets.spreadsheets.batchupdate(request, spreadsheetid); logger.log(response); }
error message:
invalid json payload received. unknown name "add_banding": cannot find field.
this sample code works (for adding new sheet): https://developers.google.com/apps-script/advanced/sheets#add_a_new_sheet
thanks help.
joerg
edit: found solution, bandedrange missing in request, sheetid needs pulled active sheet.
function addbanding() { var spreadsheetid = spreadsheetapp.getactivespreadsheet().getid(); var sheetid = spreadsheetapp.getactivespreadsheet().getactivesheet().getsheetid(); var requests = [{ "addbanding": { "bandedrange": { "bandedrangeid": 12345, "range": { "sheetid": sheetid, "startrowindex": 1, "endrowindex": 15, "startcolumnindex": 1, "endcolumnindex": 4, }, "rowproperties": { "headercolor": { "red": 1, "green": 0, "blue": 1, "alpha": 1, }, "firstbandcolor": { "red": 1, "green": 0, "blue": 0, "alpha": 0, }, "secondbandcolor": { "red": 0, "green": 1, "blue": 0, "alpha": 0, } } } } }]; var response = sheets.spreadsheets.batchupdate({"requests": requests}, spreadsheetid); logger.log(response); }
Comments
Post a Comment