Skip to content

Commit

Permalink
Add more parameters to Worksheet.append_row() (burnash#726)
Browse files Browse the repository at this point in the history
* Add two parameters to `Worksheet.append_row`:
	- `table_range`
	- `insert_data_option`

* Add tests for `Worksheet.append_row()`

* Add cassettes for tests for `Worksheet.append_row()`

Fixes burnash#537
  • Loading branch information
burnash authored Feb 17, 2020
1 parent 0f22a5d commit f063b69
Show file tree
Hide file tree
Showing 4 changed files with 3,568 additions and 7 deletions.
38 changes: 32 additions & 6 deletions gspread/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,28 +891,54 @@ def add_cols(self, cols):
"""
self.resize(cols=self.col_count + cols)

def append_row(self, values, value_input_option='RAW'):
def append_row(
self,
values,
value_input_option='RAW',
insert_data_option=None,
table_range=None
):
"""Adds a row to the worksheet and populates it with values.
Widens the worksheet if there are more values than columns.
:param values: List of values for the new row.
:param value_input_option: (optional) Determines how input data should
be interpreted. See `ValueInputOption`_ in
the Sheets API.
:param value_input_option: (optional) Determines how the input data
should be interpreted. See
`ValueInputOption`_ in the Sheets API
reference.
:type value_input_option: str
:param insert_data_option: (optional) Determines how the input data
should be inserted. See
`InsertDataOption`_ in the Sheets API
reference.
:type insert_data_option: str
:param table_range: (optional) The A1 notation of a range to search for
a logical table of data. Values are appended after
the last row of the table.
Examples: `A1` or `B2:D4`
:type table_range: str
.. _ValueInputOption: https://developers.google.com/sheets/api/reference/rest/v4/ValueInputOption
.. _InsertDataOption: https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/append#InsertDataOption
"""

range_label = (
'%s!%s' % (self.title, table_range)
if table_range
else self.title
)

params = {
'valueInputOption': value_input_option
'valueInputOption': value_input_option,
'insertDataOption': insert_data_option
}

body = {
'values': [values]
}

return self.spreadsheet.values_append(self.title, params, body)
return self.spreadsheet.values_append(range_label, params, body)

def insert_row(
self,
Expand Down
Loading

0 comments on commit f063b69

Please sign in to comment.