Exemple #1
0
    def test_offset(self):
        o = Range('A1:B3').offset(3, 4)
        assert_equal(o.get_address(), '$E$4:$F$6')

        o = Range('A1:B3').offset(row_offset=3)
        assert_equal(o.get_address(), '$A$4:$B$6')

        o = Range('A1:B3').offset(column_offset=4)
        assert_equal(o.get_address(), '$E$1:$F$3')
Exemple #2
0
    def test_offset(self):
        o = Range('A1:B3').offset(3, 4)
        assert_equal(o.get_address(), '$E$4:$F$6')

        o = Range('A1:B3').offset(row_offset=3)
        assert_equal(o.get_address(), '$A$4:$B$6')

        o = Range('A1:B3').offset(column_offset=4)
        assert_equal(o.get_address(), '$E$1:$F$3')
Exemple #3
0
def add_named_range(bk: xw.Book, rng: xw.Range, nm: str):
    """Adds a range to a book with a given name.
    Prefer to use add_named_range_from_addr

    Arguments:
        bk {xw.Book} -- Book to add named range
        rng {xw.Range} -- Range to add
        nm {str} -- name of range
    """
    add_named_range_from_addr(bk, rng.get_address(include_sheetname=True), nm)
Exemple #4
0
def create_hyperlink_to_other_cell(src_cell: xw.Range, dst_cell: xw.Range,
                                   friendly_nm: str):
    """Creates a hyperlink formula in src_cell to dst_cell with the given
    friendly_nm being the text displayed.

    Arguments:
        src_cell {xw.Range} -- cell which will contain the hyperlink.
        dst_cell {xw.Range} -- cell which the hyperlink will lead to.
        friendly_nm {str} -- text of hyperlink
    """
    link_location = '"#{}"'.format(
        dst_cell.get_address(include_sheetname=True))
    friendly_nm = '"{}"'.format(friendly_nm.replace('"', ''))

    src_cell.formula = '=HYPERLINK({}, {})'.format(link_location, friendly_nm)