Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def set_cell_value(self, x, y, value):
if DataTypes.get_type(value) == DataTypes.DATE:
self.get_cell_style(x, y).format = Format.Format('yyyy-mm-dd')
if x < len(self._dense_cells) and y < len(self._dense_cells[x]):
self._dense_cells[x][y] = value
else:
self._sparse_cells[x][y] = value
self._columns = max(self._columns, y)
def __set_attr(self, method, data):
if self.is_cell:
for merge in self.worksheet.merges:
if self in merge:
method(merge._start[0], merge._start[1], data)
return
method(self.x, self.y, data)
elif self.is_row and isinstance(data, Style.Style):
# Applying a row style
self.worksheet.set_row_style(self.x, data)
elif DataTypes.DataTypes.get_type(data) != DataTypes.DataTypes.ERROR:
# Attempt to apply in batch
for cell in self:
cell.__set_attr(method, data)
else:
if len(data) <= self.height:
for row in data:
if len(row) > self.width:
raise Exception(
"Row too large for range, row has %s columns, but range only has %s"
% (len(row), self.width))
for x, row in enumerate(data):
for y, value in enumerate(row):
method(x + self._start[0], y + self._start[1], value)
else:
raise Exception(
"Too many rows for range, data has %s rows, but range only has %s"
def __get_cell_data(self, cell, x, y, style):
if cell is None:
return "" # no cell data
# boolean values are treated oddly in dictionaries, manually override
type = DataTypes.get_type(cell)
if type == DataTypes.NUMBER:
if math.isnan(cell):
z = '" t="e">#NUM!'
elif math.isinf(cell):
z = '" t="e">#DIV/0!'
else:
z = '">%.15g' % (cell)
elif type == DataTypes.INLINE_STRING:
z = '" t="inlineStr">%s' % escape(
to_unicode(cell))
elif type == DataTypes.DATE:
z = '">%s' % (DataTypes.to_excel_date(cell))
elif type == DataTypes.FORMULA:
z = '">%s' % (cell[1:]) # Remove equals sign.
elif type == DataTypes.BOOLEAN: