def testCoordinatesToCell(self): "test coordinates_to_cell_name" self.assertEquals(coordinates_to_cell_name(1, 1), "A1", "To name test 1 failed") self.assertEquals(coordinates_to_cell_name(2, 1), "B1", "To name test 2 failed") self.assertEquals(coordinates_to_cell_name(3, 5), "C5", "To name test 3 failed") self.assertEquals(coordinates_to_cell_name(29, 100), "AC100", "To name test 4 failed") self.assertEquals(coordinates_to_cell_name(13057, 1), "SHE1", "To name test 4 failed")
def set_cell_error_and_add_to_console(worksheet, location, exception): cell = worksheet[location] cell.value = undefined cell.error = "%s: %s" % (exception.__class__.__name__, str(exception)) worksheet.add_console_text( "{error_text}\n Formula '{formula}' in {cell_name}\n".format( error_text=cell.error, formula=cell.formula, cell_name=coordinates_to_cell_name(*location) ) )
def test_coordinates_to_cell_name_bad(self): self.assertIsNone(coordinates_to_cell_name(0, 1), "bad") self.assertIsNone(coordinates_to_cell_name(1, 0), "bad") self.assertIsNone(coordinates_to_cell_name(0, 0), "bad") self.assertIsNone(coordinates_to_cell_name(1, -1), "bad") self.assertIsNone(coordinates_to_cell_name(-1, 1), "bad") self.assertIsNone(coordinates_to_cell_name(MAX_COL + 1, 1), "bad")
def offset(self, dx, dy, move_absolute=False): (col, row) = cell_name_to_coordinates(self.plainCellName) if move_absolute or not self.colAbsolute: col += dx if move_absolute or not self.rowAbsolute: row += dy newName = coordinates_to_cell_name(col, row, colAbsolute=self.colAbsolute, rowAbsolute=self.rowAbsolute) if newName is None: newName = "#Invalid!" self.localReference = newName + self.whitespace
def __repr__(self): return '<CellRange %s to %s in %s>' % (coordinates_to_cell_name( self.left, self.top), coordinates_to_cell_name( self.right, self.bottom), str(self.worksheet))
def __repr__(self): return '<CellRange %s to %s in %s>' % ( coordinates_to_cell_name(self.left, self.top), coordinates_to_cell_name(self.right, self.bottom), str(self.worksheet) )
def report_cell_error(worksheet, loc, exc): worksheet[loc].value = undefined worksheet[loc].error = "%s: %s" % (exc.__class__.__name__, str(exc)) worksheet.add_console_text("%s\n Formula '%s' in %s\n" % ( worksheet[loc].error, worksheet[loc].formula, coordinates_to_cell_name(*loc)))
def __str__(self): return ' -> '.join(coordinates_to_cell_name(*loc) for loc in self.path)
def report_cell_error(worksheet, loc, exc): worksheet[loc].value = undefined worksheet[loc].error = "%s: %s" % (exc.__class__.__name__, str(exc)) worksheet.add_console_text("%s\n Formula '%s' in %s\n" % (worksheet[loc].error, worksheet[loc].formula, coordinates_to_cell_name(*loc)))
def testCoordinatesToCell2(self): "test coordinates_to_cell_name with absolution" self.assertEquals(coordinates_to_cell_name(1, 1, colAbsolute=True), "$A1", "To name test 1 failed") self.assertEquals(coordinates_to_cell_name(2, 1, rowAbsolute=True), "B$1", "To name test 2 failed") self.assertEquals(coordinates_to_cell_name(3, 5, colAbsolute=True, rowAbsolute=True), "$C$5", "To name test 3 failed")