Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
max_cols = len(max(values, key=len))
matrix = [list(x + [''] * (max_cols - len(x))) for x in values]
else:
matrix = values
if returnas == 'matrix':
return matrix
else:
cells = []
for k in range(len(matrix)):
row = []
for i in range(len(matrix[k])):
if majdim == 'COLUMNS':
row.append(Cell((start[0]+i, start[1]+k), matrix[k][i], self))
elif majdim == 'ROWS':
row.append(Cell((start[0]+k, start[1]+i), matrix[k][i], self))
else:
raise InvalidArgumentValue('majdim')
cells.append(row)
return cells
def anchor_cell(self, new_anchor_cell):
temp = self._anchor_cell
try:
if type(new_anchor_cell) is Cell:
self._anchor_cell = (new_anchor_cell.row, new_anchor_cell.col)
self._update_position()
else:
self._anchor_cell = format_addr(new_anchor_cell, 'tuple')
self._update_position()
except:
self._anchor_cell = temp
matrix.extend([['']*max_cols]*(max_rows - len(matrix)))
elif include_empty:
max_cols = len(max(values, key=len))
matrix = [list(x + [''] * (max_cols - len(x))) for x in values]
else:
matrix = values
if returnas == 'matrix':
return matrix
else:
cells = []
for k in range(len(matrix)):
row = []
for i in range(len(matrix[k])):
if majdim == 'COLUMNS':
row.append(Cell((start[0]+i, start[1]+k), matrix[k][i], self))
elif majdim == 'ROWS':
row.append(Cell((start[0]+k, start[1]+i), matrix[k][i], self))
else:
raise InvalidArgumentValue('majdim')
cells.append(row)
return cells
"""
try:
if type(addr) is str:
val = self.client.get_range(self.spreadsheet.id, self._get_range(addr, addr), 'ROWS')[0][0]
elif type(addr) is tuple:
label = format_addr(addr, 'label')
val = self.client.get_range(self.spreadsheet.id, self._get_range(label, label), 'ROWS')[0][0]
else:
raise CellNotFound
except Exception as e:
if str(e).find('exceeds grid limits') != -1:
raise CellNotFound
else:
raise
return Cell(addr, val, self)