I have figured out a way to add a new worksheet to a an existing spreadsheet BUT I can't seem to figure out how to format the added worksheet.
For example, I can color the header row of the first worksheet (that is the default worksheet) in a spreadsheet using the method below:
def color_header_row(file)
spreadsheet_id = file.id
requests = {
requests: [
{
repeat_cell: {
range: {
sheet_id: 0,
start_row_index: 0,
end_row_index: 1
},
cell: {
user_entered_format: {
background_color: { red: 0.0, green: 0.4, blue: 0.0 },
horizontal_alignment: "CENTER",
text_format: {
foreground_color: {
red: 1.0,
green: 1.0,
blue: 1.0
},
font_size: 12,
bold: true
}
}
},
fields: 'userEnteredFormat(backgroundColor,textFormat,horizontalAlignment)'
},
}
]
}
sheet_service.batch_update_spreadsheet(spreadsheet_id, requests, {})
end
Notice that the default worksheet sheet_id is 0 thus my assumption (given how GridRange is defined in the documentation) was that setting sheet_id to 1 will result in a reference to the newly added worksheet (in essence worksheet at position 1). Yet when sheet_id is set to 1, the error Invalid request(Google::Apis::ClientError) is returned.
Any idea on how to format the header row of a non-default (that is a worksheet that isn't the in the first position in a spreadsheet) worksheet?