Work with ranges
This commit is contained in:
parent
f4b8d95444
commit
5e73b560d4
|
@ -3426,7 +3426,7 @@ class LODocCalc(LODocument):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def ranges(self):
|
def ranges(self):
|
||||||
obj = self.create_instance('com.sun.star.sheet.SheetCellRanges')
|
obj = self._create_instance('com.sun.star.sheet.SheetCellRanges')
|
||||||
return LOCalcRanges(obj)
|
return LOCalcRanges(obj)
|
||||||
|
|
||||||
def get_ranges(self, address: str):
|
def get_ranges(self, address: str):
|
||||||
|
@ -3564,6 +3564,41 @@ class LOCalcRanges(object):
|
||||||
def __init__(self, obj):
|
def __init__(self, obj):
|
||||||
self._obj = obj
|
self._obj = obj
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, exc_type, exc_value, traceback):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def __len__(self):
|
||||||
|
return self._obj.Count
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
self._index = 0
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __next__(self):
|
||||||
|
try:
|
||||||
|
r = self.obj[self._index]
|
||||||
|
rango = LOCalcRange(r)
|
||||||
|
except IndexError:
|
||||||
|
raise StopIteration
|
||||||
|
|
||||||
|
self._index += 1
|
||||||
|
return rango
|
||||||
|
|
||||||
|
def __contains__(self, item):
|
||||||
|
return self._obj.hasByName(item.name)
|
||||||
|
|
||||||
|
def __getitem__(self, index):
|
||||||
|
r = self.obj[index]
|
||||||
|
rango = LOCalcRange(r)
|
||||||
|
return rango
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
s = f'Ranges: {self.names}'
|
||||||
|
return s
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def obj(self):
|
def obj(self):
|
||||||
return self._obj
|
return self._obj
|
||||||
|
@ -3572,14 +3607,37 @@ class LOCalcRanges(object):
|
||||||
def names(self):
|
def names(self):
|
||||||
return self.obj.ElementNames
|
return self.obj.ElementNames
|
||||||
|
|
||||||
def add(self, rangos):
|
@property
|
||||||
|
def data(self):
|
||||||
|
rows = [r.data for r in self]
|
||||||
|
return rows
|
||||||
|
@data.setter
|
||||||
|
def data(self, values):
|
||||||
|
for i, data in enumerate(values):
|
||||||
|
self[i].data = data
|
||||||
|
|
||||||
|
@property
|
||||||
|
def style(self):
|
||||||
|
return ''
|
||||||
|
@style.setter
|
||||||
|
def style(self, value):
|
||||||
|
for r in self:
|
||||||
|
r.style = value
|
||||||
|
|
||||||
|
def add(self, rangos: Any):
|
||||||
if isinstance(rangos, LOCalcRange):
|
if isinstance(rangos, LOCalcRange):
|
||||||
rangos = (rangos,)
|
rangos = (rangos,)
|
||||||
for r in rangos:
|
for r in rangos:
|
||||||
# ~ self._ranges[r.name] = r
|
|
||||||
self.obj.addRangeAddress(r.range_address, False)
|
self.obj.addRangeAddress(r.range_address, False)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def remove(self, rangos: Any):
|
||||||
|
if isinstance(rangos, LOCalcRange):
|
||||||
|
rangos = (rangos,)
|
||||||
|
for r in rangos:
|
||||||
|
self.obj.removeRangeAddress(r.range_address)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
class LOCalcRange(object):
|
class LOCalcRange(object):
|
||||||
CELL = 'ScCellObj'
|
CELL = 'ScCellObj'
|
||||||
|
@ -3653,6 +3711,13 @@ class LOCalcRange(object):
|
||||||
def sheet(self):
|
def sheet(self):
|
||||||
return LOCalcSheet(self.obj.Spreadsheet)
|
return LOCalcSheet(self.obj.Spreadsheet)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def style(self):
|
||||||
|
return self.obj.CellStyle
|
||||||
|
@style.setter
|
||||||
|
def style(self, value):
|
||||||
|
self.obj.CellStyle = value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def cursor(self):
|
def cursor(self):
|
||||||
cursor = self.obj.Spreadsheet.createCursorByRange(self.obj)
|
cursor = self.obj.Spreadsheet.createCursorByRange(self.obj)
|
||||||
|
|
Loading…
Reference in New Issue