Skip to content

Commit

Permalink
[WIP] Moved sh_append to sheet API.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kordishal committed Jun 6, 2018
1 parent adb6636 commit 94c7b7c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
10 changes: 1 addition & 9 deletions pygsheets/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,7 @@ def sh_copy_worksheet(self, src_ssheet, src_worksheet, dst_ssheet):
return self._execute_request(dst_ssheet, final_request, False)

def sh_append(self, spreadsheet_id, body, rranage, replace=False, batch=False):
"""wrapper around batch append"""
if replace:
inoption = "OVERWRITE"
else:
inoption = "INSERT_ROWS"
final_request = self.service.spreadsheets().values().append(spreadsheetId=spreadsheet_id, range=rranage, body=body,
insertDataOption=inoption, includeValuesInResponse=False,
valueInputOption="USER_ENTERED")
self._execute_request(spreadsheet_id, final_request, batch)
""""""

# @TODO use batch update more efficiently
def sh_batch_update(self, spreadsheet_id, request, fields=None, batch=False):
Expand Down
19 changes: 17 additions & 2 deletions pygsheets/sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,23 @@ def sheets_copy_to(self, source_spreadsheet_id, worksheet_id, destination_spread
**kwargs)
return self._execute_requests(request)

def values_append(self):
pass
def values_append(self, spreadsheet_id, values, major_dimension, range, replace):
"""wrapper around batch append"""
body = {
'values': values,
'majorDimension': major_dimension
}

if replace:
inoption = "OVERWRITE"
else:
inoption = "INSERT_ROWS"
request = self.service.spreadsheets().values().append(spreadsheetId=spreadsheet_id, range=range,
body=body,
insertDataOption=inoption,
includeValuesInResponse=False,
valueInputOption="USER_ENTERED")
self._execute_requests(request)

def values_batch_clear(self):
pass
Expand Down
15 changes: 9 additions & 6 deletions pygsheets/worksheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,24 +796,27 @@ def adjust_row_height(self, start, end=None, pixel_size=100):
}
self.client.sh_batch_update(self.spreadsheet.id, request, batch=self.spreadsheet.batch_mode)

def append_table(self, start='A1', end=None, values=None, dimension='ROWS', overwrite=False):
"""Append values to the sheet.
def append_table(self, values, start='A1', end=None, dimension='ROWS', overwrite=False):
"""Append a row or column of values.
#TODO: How does this actually work?
This will append the list of provided values to the
Reference: https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/append
:param values: List of values for the new row or column.
:param start: Top left cell of the range (requires a label).
:param end: Bottom right cell of the range (requires a label).
:param values: List of values for the new row or column.
:param dimension: Dimension to which the values will be added ('ROWS' or 'COLUMNS')
:param overwrite: Overwrite existing values.
"""

if type(values[0]) != list:
values = [values]
if not end:
end = (self.rows, self.cols)
body = {"values": values, "majorDimension": dimension}
self.client.sh_append(self.spreadsheet.id, body=body, rranage=self._get_range(start, end), replace=overwrite)
self.client.sheet.values_append(self.spreadsheet.id, values, dimension, range=self._get_range(start, end),
replace=overwrite)

def replace(self, pattern, replacement=None, **kwargs):
"""Replace values in any cells matched by pattern in this worksheet.
Expand Down

0 comments on commit 94c7b7c

Please sign in to comment.