-
Notifications
You must be signed in to change notification settings - Fork 508
Add Spreadsheet#append using the dedicated Google Drive API #349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 6 commits
d0e1850
0bab64b
34c2ccb
2b05d3a
a9d9b81
37ab353
eeff555
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -131,5 +131,37 @@ def batch_update(requests) | |
| @session.sheets_service.batch_update_spreadsheet(id, batch_request) | ||
| batch_response.replies | ||
| end | ||
|
|
||
| # Append values to a spreadsheet by first searching for a data table at a range, | ||
| # then appending the specified values at the end of this data table. | ||
| # | ||
| # +range+ The A1 notation of a range to search for a logical table of data. | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still don't understand how it determines the worksheet (i.e., tab) which the value is added to. Assuming the spreadsheet has two worksheets "Sheet 1" and "Sheet 2", and you specify "A1" here, does it add values to A1 of Sheet 1 or Sheet 2? Do you know?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am sorry, I don't have more information than what Google provides at https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/append There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@gimite You can specify "Sheet1!A1". You can find examples in the following URL. |
||
| # Values will be appended after the last row of the table. | ||
| # +values+ Array (rows) of Array (columns) of values to append to the spreadsheet. | ||
| # +override_params+ allows you to control how the values will be inserted. | ||
genezys marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # By default, the values will be interpreted as if typed by a user, | ||
| # and will add new rows instead of ovewriting existing ones. | ||
genezys marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # So default value is `{ value_input_option: 'USER_ENTERED', insert_data_option: 'INSERT_ROWS' }` | ||
| # See https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/append#query-parameters for more information | ||
| # | ||
| # Returns an object +UpdateValuesResponse+ that documents the modifications done | ||
| # to your spreadsheet. | ||
| # | ||
| # You can read the Google documentation for more information: | ||
| # https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/append | ||
| # | ||
| # Example: | ||
| # sheet.append_values "A1", [ [ 10, 11, 12 ], [ 20, 21, 22 ] ] | ||
| # | ||
| def append_values(range_name, values, override_params = {}) | ||
| value_range = Google::Apis::SheetsV4::ValueRange.new(values: values) | ||
| default_params = { | ||
| value_input_option: 'USER_ENTERED', | ||
| insert_data_option: 'INSERT_ROWS', | ||
| } | ||
| request_body = default_params.merge(override_params) | ||
| result = @session.sheets_service.append_spreadsheet_value(id, range_name, value_range, request_body) | ||
| result.updates | ||
genezys marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| end | ||
| end | ||
| end | ||
Uh oh!
There was an error while loading. Please reload this page.