Esempio n. 1
0
def divide_range(cell_range, by="columns"):
    """
    Returns a list of cell range (string) divided in columns or rows

    cell_range -- str like Sheet.A1:Sheet.C5
    by -- 'columns' 'rows'
    """
    my_list = []
    sheet1=splitfields(splitfields(cell_range, ":")[0],".")[0]
    cell1=splitfields(splitfields(cell_range, ":")[0],".")[1]
    sheet2=splitfields(splitfields(cell_range, ":")[1],".")[0]
    cell2=splitfields(splitfields(cell_range, ":")[1],".")[1]
    
    tmp_coord1 = _get_cell_coordinates(cell1)
    tmp_coord2 = _get_cell_coordinates(cell2)

    #we need the coordinate in a crescent order
    coord1 = (min(tmp_coord1[0], tmp_coord2[0]),min(tmp_coord1[1],
                                                                tmp_coord2[1]))

    coord2 = (max(tmp_coord1[0], tmp_coord2[0]),max(tmp_coord1[1],
                                                                tmp_coord2[1]))


    if by == 'columns':
        for i in range(coord1[0], coord2[0]+1):
	    tmp_cell_range = sheet1 + "." + _digit_to_alpha(i) + \
			     str(coord1[1]+1) + ":" + sheet2 + "." + \
                             _digit_to_alpha(i) + str(coord2[1]+1)

            my_list.append(tmp_cell_range)
        return my_list
        
    elif by == 'rows':
        for i in range(coord1[1], coord2[1]+1):
	    tmp_cell_range = sheet1 + "." + _digit_to_alpha(coord1[0]) + \
			     str(i+1) + ":" + sheet2 + "." + \
                             _digit_to_alpha(coord2[0]) + str(i+1) \

            my_list.append(tmp_cell_range)
        return my_list

    else:
        raise AttributeError
Esempio n. 2
0
def divide_range(cell_range, by="columns"):
    """
    Returns a list of cell range (string) divided in columns or rows

    cell_range -- str like Sheet.A1:Sheet.C5
    by -- 'columns' 'rows'
    """
    my_list = []
    sheet1 = splitfields(splitfields(cell_range, ":")[0], ".")[0]
    cell1 = splitfields(splitfields(cell_range, ":")[0], ".")[1]
    sheet2 = splitfields(splitfields(cell_range, ":")[1], ".")[0]
    cell2 = splitfields(splitfields(cell_range, ":")[1], ".")[1]

    tmp_coord1 = _get_cell_coordinates(cell1)
    tmp_coord2 = _get_cell_coordinates(cell2)

    #we need the coordinate in a crescent order
    coord1 = (min(tmp_coord1[0],
                  tmp_coord2[0]), min(tmp_coord1[1], tmp_coord2[1]))

    coord2 = (max(tmp_coord1[0],
                  tmp_coord2[0]), max(tmp_coord1[1], tmp_coord2[1]))

    if by == 'columns':
        for i in range(coord1[0], coord2[0] + 1):
            tmp_cell_range = sheet1 + "." + _digit_to_alpha(i) + \
               str(coord1[1]+1) + ":" + sheet2 + "." + \
                                    _digit_to_alpha(i) + str(coord2[1]+1)

            my_list.append(tmp_cell_range)
        return my_list

    elif by == 'rows':
        for i in range(coord1[1], coord2[1] + 1):
            tmp_cell_range = sheet1 + "." + _digit_to_alpha(coord1[0]) + \
               str(i+1) + ":" + sheet2 + "." + \
                                    _digit_to_alpha(coord2[0]) + str(i+1) \

            my_list.append(tmp_cell_range)
        return my_list

    else:
        raise AttributeError
Esempio n. 3
0
def split_range(cell_range, legend="row", x_labels="column"):
    """
    returns a dictionnary with data_range, legend_range and labels for the
    x-axis

    cell_range - str like Sheet.A1:SheetD5
    legend, x_labels - 'none', 'row', 'column'
    """

    my_dict = {"data":cell_range, "legend":"", "labels":""}
    sheet1=splitfields(splitfields(cell_range, ":")[0],".")[0]
    cell1=splitfields(splitfields(cell_range, ":")[0],".")[1]
    sheet2=splitfields(splitfields(cell_range, ":")[1],".")[0]
    cell2=splitfields(splitfields(cell_range, ":")[1],".")[1]
    
    tmp_coord1 = _get_cell_coordinates(cell1)
    tmp_coord2 = _get_cell_coordinates(cell2)

    #we need the coordinate in a crescent order
    coord1 = (min(tmp_coord1[0], tmp_coord2[0]),min(tmp_coord1[1],
                                                                tmp_coord2[1]))

    coord2 = (max(tmp_coord1[0], tmp_coord2[0]),max(tmp_coord1[1],
                                                                tmp_coord2[1]))


    if legend is not 'none' and x_labels is not 'none':
        #if we have both conditions, we have to delete the first cell
        if legend == "row":
	    my_dict["legend"] = sheet1 + "." + _digit_to_alpha(coord1[0]+1) + \
			        str(coord1[1]+1) + ":"+sheet2 + "." + \
                                _digit_to_alpha(coord2[0]) + str(coord1[1]+1)

        elif legend == "column":
	    my_dict["legend"] = sheet1 + "." + _digit_to_alpha(coord1[0]) + \
				str(coord1[1]+2) + ":"+sheet2 + "." + \
                                _digit_to_alpha(coord1[0]) + str(coord2[1]+1) 

        if x_labels == "row":
	    my_dict["labels"] = sheet1 + "." + _digit_to_alpha(coord1[0]+1) + \
				str(coord1[1]+1) + ":"+sheet2 + "." + \
                                _digit_to_alpha(coord2[0]) + str(coord1[1]+1)

        elif x_labels == "column":
	    my_dict["labels"] = sheet1 + "." + _digit_to_alpha(coord1[0]) + \
				str(coord1[1]+2) + ":"+sheet2 + "." + \
                                _digit_to_alpha(coord1[0]) + str(coord2[1]+1)


	my_dict["data"] = sheet1 + "." + _digit_to_alpha(coord1[0]+1) + \
			  str(coord1[1]+2) + ":"+sheet2 + "." + \
                          _digit_to_alpha(coord2[0]) + str(coord2[1]+1)

    else:
        if legend == "row":
	    my_dict["legend"] = sheet1 + "." + _digit_to_alpha(coord1[0]) + \
				str(coord1[1]+1) + ":"+sheet2 + "." + \
                                _digit_to_alpha(coord2[0]) + str(coord1[1]+1)

	    my_dict["data"] = sheet1 + "." + _digit_to_alpha(coord1[0]) + \
			      str(coord1[1]+2) + ":" + sheet2 + "." + \
                              _digit_to_alpha(coord2[0]) + str(coord2[1]+1)

        elif legend == "column":
	    my_dict["legend"] = sheet1 + "." + _digit_to_alpha(coord1[0]) + \
				str(coord1[1]+1) + ":"+sheet2 + "." + \
                                _digit_to_alpha(coord1[0]) + str(coord2[1]+1)

	    my_dict["data"] = sheet1 + "." + _digit_to_alpha(coord1[0]+1) + \
			      str(coord1[1]+1) + ":"+sheet2 + \
                              "."+_digit_to_alpha(coord2[0]) + str(coord2[1]+1)

        if x_labels == "row":
	    my_dict["labels"] = sheet1 + "." + _digit_to_alpha(coord1[0]) + \
				str(coord1[1]+1) + ":" + sheet2 + "." + \
                                _digit_to_alpha(coord2[0]) + str(coord1[1]+1)

	    my_dict["data"] = sheet1 + "." + _digit_to_alpha(coord1[0]) + \
			      str(coord1[1]+2) + ":"+sheet2 + "." + \
                              _digit_to_alpha(coord2[0]) + str(coord2[1]+1)

        elif x_labels == "column":
	    my_dict["labels"] = sheet1 + "." + _digit_to_alpha(coord1[0]) + \
				str(coord1[1]+1) + ":"+sheet2 + "." + \
                                _digit_to_alpha(coord1[0]) + str(coord2[1]+1)

	    my_dict["data"] = sheet1 + "."+ _digit_to_alpha(coord1[0]+1) + \
			      str(coord1[1]+1) + ":"+sheet2 + "." + \
                              _digit_to_alpha(coord2[0]) + str(coord2[1]+1)


    return my_dict
Esempio n. 4
0
 def test_get_cell_coordinates_alphanum(self):
     x, y = _get_cell_coordinates('ABC123')
     self.assertEqual((x, y), (730, 122))
Esempio n. 5
0
 def test_get_cell_coordinates_tuple(self):
     x1, y1 = (12, 34)
     x2, y2 = _get_cell_coordinates((x1, y1))
     self.assertEqual((x1, y1), (x2, y2))
Esempio n. 6
0
def split_range(cell_range, legend="row", x_labels="column"):
    """
    returns a dictionnary with data_range, legend_range and labels for the
    x-axis

    cell_range - str like Sheet.A1:SheetD5
    legend, x_labels - 'none', 'row', 'column'
    """

    my_dict = {"data": cell_range, "legend": "", "labels": ""}
    sheet1 = splitfields(splitfields(cell_range, ":")[0], ".")[0]
    cell1 = splitfields(splitfields(cell_range, ":")[0], ".")[1]
    sheet2 = splitfields(splitfields(cell_range, ":")[1], ".")[0]
    cell2 = splitfields(splitfields(cell_range, ":")[1], ".")[1]

    tmp_coord1 = _get_cell_coordinates(cell1)
    tmp_coord2 = _get_cell_coordinates(cell2)

    #we need the coordinate in a crescent order
    coord1 = (min(tmp_coord1[0],
                  tmp_coord2[0]), min(tmp_coord1[1], tmp_coord2[1]))

    coord2 = (max(tmp_coord1[0],
                  tmp_coord2[0]), max(tmp_coord1[1], tmp_coord2[1]))

    if legend is not 'none' and x_labels is not 'none':
        #if we have both conditions, we have to delete the first cell
        if legend == "row":
            my_dict["legend"] = sheet1 + "." + _digit_to_alpha(coord1[0]+1) + \
                  str(coord1[1]+1) + ":"+sheet2 + "." + \
                                       _digit_to_alpha(coord2[0]) + str(coord1[1]+1)

        elif legend == "column":
            my_dict["legend"] = sheet1 + "." + _digit_to_alpha(coord1[0]) + \
           str(coord1[1]+2) + ":"+sheet2 + "." + \
                                       _digit_to_alpha(coord1[0]) + str(coord2[1]+1)

        if x_labels == "row":
            my_dict["labels"] = sheet1 + "." + _digit_to_alpha(coord1[0]+1) + \
           str(coord1[1]+1) + ":"+sheet2 + "." + \
                                       _digit_to_alpha(coord2[0]) + str(coord1[1]+1)

        elif x_labels == "column":
            my_dict["labels"] = sheet1 + "." + _digit_to_alpha(coord1[0]) + \
           str(coord1[1]+2) + ":"+sheet2 + "." + \
                                       _digit_to_alpha(coord1[0]) + str(coord2[1]+1)


        my_dict["data"] = sheet1 + "." + _digit_to_alpha(coord1[0]+1) + \
            str(coord1[1]+2) + ":"+sheet2 + "." + \
                                 _digit_to_alpha(coord2[0]) + str(coord2[1]+1)

    else:
        if legend == "row":
            my_dict["legend"] = sheet1 + "." + _digit_to_alpha(coord1[0]) + \
           str(coord1[1]+1) + ":"+sheet2 + "." + \
                                       _digit_to_alpha(coord2[0]) + str(coord1[1]+1)

            my_dict["data"] = sheet1 + "." + _digit_to_alpha(coord1[0]) + \
                str(coord1[1]+2) + ":" + sheet2 + "." + \
                                     _digit_to_alpha(coord2[0]) + str(coord2[1]+1)

        elif legend == "column":
            my_dict["legend"] = sheet1 + "." + _digit_to_alpha(coord1[0]) + \
           str(coord1[1]+1) + ":"+sheet2 + "." + \
                                       _digit_to_alpha(coord1[0]) + str(coord2[1]+1)

            my_dict["data"] = sheet1 + "." + _digit_to_alpha(coord1[0]+1) + \
                str(coord1[1]+1) + ":"+sheet2 + \
                                     "."+_digit_to_alpha(coord2[0]) + str(coord2[1]+1)

        if x_labels == "row":
            my_dict["labels"] = sheet1 + "." + _digit_to_alpha(coord1[0]) + \
           str(coord1[1]+1) + ":" + sheet2 + "." + \
                                       _digit_to_alpha(coord2[0]) + str(coord1[1]+1)

            my_dict["data"] = sheet1 + "." + _digit_to_alpha(coord1[0]) + \
                str(coord1[1]+2) + ":"+sheet2 + "." + \
                                     _digit_to_alpha(coord2[0]) + str(coord2[1]+1)

        elif x_labels == "column":
            my_dict["labels"] = sheet1 + "." + _digit_to_alpha(coord1[0]) + \
           str(coord1[1]+1) + ":"+sheet2 + "." + \
                                       _digit_to_alpha(coord1[0]) + str(coord2[1]+1)

            my_dict["data"] = sheet1 + "."+ _digit_to_alpha(coord1[0]+1) + \
                str(coord1[1]+1) + ":"+sheet2 + "." + \
                                     _digit_to_alpha(coord2[0]) + str(coord2[1]+1)

    return my_dict
Esempio n. 7
0
 def test_get_cell_coordinates_alphanum(self):
     x, y = _get_cell_coordinates('ABC123')
     self.assertEqual((x, y), (730, 122))
Esempio n. 8
0
 def test_get_cell_coordinates_tuple(self):
     x1, y1 = (12, 34)
     x2, y2 = _get_cell_coordinates((x1, y1))
     self.assertEqual((x1, y1), (x2, y2))