Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def range(self, arg1, arg2=None):
if isinstance(arg1, Range):
xl1 = arg1.xl
else:
xl1 = self.xl.Range(arg1)
if arg2 is None:
return Range(xl=xl1)
if isinstance(arg2, Range):
xl2 = arg2.xl
else:
xl2 = self.xl.Range(arg2)
return Range(xl=self.xl.Range(xl1, xl2))
def refers_to_range(self):
return Range(xl=self.xl.RefersToRange)
def __call__(self, *args):
if self.xl is not None:
if len(args) == 0:
raise ValueError("Invalid arguments")
return Range(xl=self.xl(*args))
else:
raise NotImplemented()
xl1 = arg1.xl
elif isinstance(arg1, tuple):
if len(arg1) == 4:
row, col, nrows, ncols = arg1
return Range(xl=(self.xl, row, col, nrows, ncols))
if 0 in arg1:
raise IndexError("Attempted to access 0-based Range. xlwings/Excel Ranges are 1-based.")
xl1 = self.xl.Cells(arg1[0], arg1[1])
elif isinstance(arg1, numbers.Number) and isinstance(arg2, numbers.Number):
xl1 = self.xl.Cells(arg1, arg2)
arg2 = None
else:
xl1 = self.xl.Range(arg1)
if arg2 is None:
return Range(xl=xl1)
if isinstance(arg2, Range):
xl2 = arg2.xl
elif isinstance(arg2, tuple):
if 0 in arg2:
raise IndexError("Attempted to access 0-based Range. xlwings/Excel Ranges are 1-based.")
xl2 = self.xl.Cells(arg2[0], arg2[1])
else:
xl2 = self.xl.Range(arg2)
return Range(xl=self.xl.Range(xl1, xl2))
def range(self, arg1, arg2=None):
if isinstance(arg1, Range):
xl1 = arg1.xl
else:
xl1 = self.xl.Range(arg1)
if arg2 is None:
return Range(xl=xl1)
if isinstance(arg2, Range):
xl2 = arg2.xl
else:
xl2 = self.xl.Range(arg2)
return Range(xl=self.xl.Range(xl1, xl2))
def selection(self):
try:
_ = self.xl.Selection.Address # Force an exception outside of the retry wrapper if e.g. a chart is selected
return Range(xl=self.xl.Selection)
except pywintypes.com_error:
return None
def range(self, arg1, arg2=None):
if isinstance(arg1, Range):
xl1 = arg1.xl
else:
xl1 = self.xl.Range(arg1)
if arg2 is None:
return Range(xl=xl1)
if isinstance(arg2, Range):
xl2 = arg2.xl
else:
xl2 = self.xl.Range(arg2)
return Range(xl=self.xl.Range(xl1, xl2))
def end(self, direction):
direction = directions_s2i.get(direction, direction)
return Range(xl=self.xl.End(direction))
def cells(self):
return Range(xl=self.xl.Cells)
def current_region(self):
if self.xl is not None:
return Range(xl=self.xl.CurrentRegion)
else:
return self