Ok, here is the answer which I consider is very much different code from the suggested duplicate and which reference to should be removed. This code includes methods for querying sheet properties and updating values and appending new columns to a sheet.
This answer should be read in conjunction with https://developers.google.com/drive/v3/web/quickstart/ruby
Common code:
service = Google::Apis::SheetsV4::SheetsService.new
service.client_options.application_name = APPLICATION_NAME
service.authorization = authorize
Adding a new sheet:
sheet_name = '2020'
column_count = 55
add_sheet_request = Google::Apis::SheetsV4::AddSheetRequest.new
add_sheet_request.properties = Google::Apis::SheetsV4::SheetProperties.new
add_sheet_request.properties.title = sheet_name
grid_properties = Google::Apis::SheetsV4::GridProperties.new
grid_properties.column_count = column_count
add_sheet_request.properties.grid_properties = grid_properties
batch_update_spreadsheet_request = Google::Apis::SheetsV4::BatchUpdateSpreadsheetRequest.new
batch_update_spreadsheet_request.requests = Google::Apis::SheetsV4::Request.new
batch_update_spreadsheet_request_object = [ add_sheet: add_sheet_request ]
batch_update_spreadsheet_request.requests = batch_update_spreadsheet_request_object
response = service.batch_update_spreadsheet(spreadsheet_id,
batch_update_spreadsheet_request)
puts ">>>>>>>>>> response: #{response.inspect}"
Updating spreadsheet values:
range = 'Sheet1!A1:C2'
value_range_object = {
"major_dimension": "ROWS",
"values": [
["Multiplicand", "Multiplier", "Result"],
["2", "8", "=A2*B2"]
]
}
response = service.clear_values(spreadsheet_id, "Sheet1!A1:Z99")
response = service.update_spreadsheet_value(spreadsheet_id, range,
value_range_object, value_input_option: 'USER_ENTERED')
Getting a spreadsheet's properties, title, and column count:
response = service.get_spreadsheet(spreadsheet_id)
puts ">>>>>>>>>> response: #{response.inspect}"
response.sheets.each do |s|
puts s.properties.sheet_id
puts s.properties.index
puts s.properties.title
puts s.properties.grid_properties.column_count
end
Appending new columns to a sheet:
append_dimension_request = Google::Apis::SheetsV4::AppendDimensionRequest.new
append_dimension_request.dimension = 'COLUMNS'
append_dimension_request.length = 30
append_dimension_request.sheet_id = 1491311133
batch_update_spreadsheet_request = Google::Apis::SheetsV4::BatchUpdateSpreadsheetRequest.new
batch_update_spreadsheet_request.requests = Google::Apis::SheetsV4::Request.new
batch_update_spreadsheet_request_object = [ append_dimension: append_dimension_request ]
batch_update_spreadsheet_request.requests = batch_update_spreadsheet_request_object
response = service.batch_update_spreadsheet(spreadsheet_id, batch_update_spreadsheet_request)