Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
def insert_row_at(self, values, row_idx):
""""Adds a row to the beginning of 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.
"""
self.add_rows(1)
data_width = len(values)
if self.col_count < data_width:
self.resize(cols=data_width)
all_cells = self.get_all_values()
lower_rows = [row:len(all_cells)]
lower_rows.insert(0, values)
updated_cell_list=[]
for r, row in enumerate(lower_rows, start=row):
for c, cell in enumerate(row, start=1):
ncell = self.cell(r, c)
ncell.value = all_cells[r-1][c-1]
updated_cell_list.append(ncell)
self.update_cells(updated_cell_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.