Skip to content

Commit

Permalink
added Range.offset(), closes #89
Browse files Browse the repository at this point in the history
  • Loading branch information
fzumstein committed Nov 25, 2014
1 parent 208a048 commit a59fd6a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
29 changes: 26 additions & 3 deletions xlwings/main.py
Expand Up @@ -937,11 +937,11 @@ def color(self, color_or_rgb):

def resize(self, row_size=None, column_size=None):
"""
Resizes the specified range.
Resizes the specified Range.
Returns
-------
Range : a Range object that represents the resized Range.
Range : Range object
"""
if row_size:
row2 = self.row1 + row_size - 1
Expand All @@ -952,7 +952,30 @@ def resize(self, row_size=None, column_size=None):
else:
col2 = self.col1

return Range((self.row1, self.col1),(row2, col2))
return Range((self.row1, self.col1), (row2, col2))

def offset(self, row_offset=None, column_offset=None):
"""
Returns a Range object that represents a Range that's offset from the specified range.
Returns
-------
Range : Range object
"""

if row_offset:
row1 = self.row1 + row_offset
row2 = self.row2 + row_offset
else:
row1, row2 = self.row1, self.row2

if column_offset:
col1 = self.col1 + column_offset
col2 = self.col2 + column_offset
else:
col1, col2 = self.col1, self.col2

return Range((row1, col1), (row2, col2))


class Chart(object):
Expand Down
12 changes: 11 additions & 1 deletion xlwings/tests/test_xlwings.py
Expand Up @@ -669,9 +669,19 @@ def test_resize(self):
r = Range('A1').resize(row_size=4)
assert_equal(r.shape, (4, 1))

r = Range('A1').resize(column_size=5)
r = Range('A1:B4').resize(column_size=5)
assert_equal(r.shape, (1, 5))

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')


class TestChart:
def setUp(self):
Expand Down

0 comments on commit a59fd6a

Please sign in to comment.