Skip to content
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

Add insert_cols method to worksheet #802

Merged
merged 1 commit into from
Oct 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions gspread/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,43 @@ def insert_rows(self, values, row=1, value_input_option='RAW'):

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

def insert_cols(self, values, col=1, value_input_option='RAW'):
"""Adds multiple new cols to the worksheet at specified index and
populates them with values.

:param list values: List of col lists. a list of lists, with the lists
each containing one col's values. Increases the number of rows
if there are more values than columns.
:param int row: Start col to update(one-based). Defaults to 1 (one).
:param str value_input_option: (optional) Determines how input data
should be interpreted. Possible values are ``RAW`` or
``USER_ENTERED``. See `ValueInputOption`_ in the Sheets API.
"""
body = {
"requests": [
{
"insertDimension": {
"range": {
"sheetId": self.id,
"dimension": "COLUMNS",
"startIndex": col - 1,
"endIndex": len(values) + col - 1,
}
}
}
]
}

self.spreadsheet.batch_update(body)

range_label = absolute_range_name(self.title, rowcol_to_a1(1, col))

params = {'valueInputOption': value_input_option}

body = {'majorDimension': 'COLUMNS', 'values': values}

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

def delete_row(self, index):
"""Deletes the row from the worksheet at the specified index.

Expand Down