Add search by range
This commit is contained in:
parent
bd350aa01f
commit
fea2a3ae43
|
@ -272,13 +272,6 @@ class LOBase(object):
|
|||
|
||||
class LOCellRange(object):
|
||||
|
||||
@property
|
||||
def cell_style(self):
|
||||
return self.obj.CellStyle
|
||||
@cell_style.setter
|
||||
def cell_style(self, value):
|
||||
self.obj.CellStyle = value
|
||||
|
||||
@property
|
||||
def auto_format(self):
|
||||
return self.obj.CellStyle
|
||||
|
@ -286,41 +279,6 @@ class LOCellRange(object):
|
|||
def auto_format(self, value):
|
||||
self.obj.autoFormat(value)
|
||||
|
||||
def get_column(self, index=0, first=False):
|
||||
ca = self.address
|
||||
ra = self.current_region.address
|
||||
if hasattr(ca, 'Column'):
|
||||
col = ca.Column
|
||||
else:
|
||||
col = ca.StartColumn + index
|
||||
start = 1
|
||||
if first:
|
||||
start = 0
|
||||
if hasattr(ra, 'Row'):
|
||||
row_start = ra.Row + start
|
||||
row_end = ra.Row + 1
|
||||
else:
|
||||
row_start = ra.StartRow + start
|
||||
row_end = ra.EndRow + 1
|
||||
return LOCellRange(self.sheet[row_start:row_end, col:col+1].obj, self.doc)
|
||||
|
||||
def search(self, options):
|
||||
descriptor = self.obj.Spreadsheet.createSearchDescriptor()
|
||||
descriptor.setSearchString(options.get('Search', ''))
|
||||
descriptor.SearchCaseSensitive = options.get('CaseSensitive', False)
|
||||
descriptor.SearchWords = options.get('Words', False)
|
||||
if hasattr(descriptor, 'SearchRegularExpression'):
|
||||
descriptor.SearchRegularExpression = options.get('RegularExpression', False)
|
||||
if hasattr(descriptor, 'SearchType') and 'Type' in options:
|
||||
descriptor.SearchType = options['Type']
|
||||
|
||||
if options.get('First', False):
|
||||
found = self.obj.findFirst(descriptor)
|
||||
else:
|
||||
found = self.obj.findAll(descriptor)
|
||||
|
||||
return found
|
||||
|
||||
def replace(self, options):
|
||||
descriptor = self.obj.Spreadsheet.createReplaceDescriptor()
|
||||
descriptor.setSearchString(options['Search'])
|
||||
|
|
|
@ -2046,6 +2046,10 @@ class LOCalcSheet(object):
|
|||
# ~ e.replaceByName(k, args)
|
||||
uno.invoke(ev, 'replaceByName', (name, uno.Any(pv, args)))
|
||||
|
||||
@property
|
||||
def search_descriptor(self):
|
||||
return self.obj.createSearchDescriptor()
|
||||
|
||||
def activate(self):
|
||||
self.doc.activate(self.obj)
|
||||
return
|
||||
|
@ -2378,10 +2382,42 @@ class LOCalcRange(object):
|
|||
def merge(self, value):
|
||||
self.obj.merge(value)
|
||||
|
||||
@property
|
||||
def style(self):
|
||||
return self.obj.CellStyle
|
||||
@style.setter
|
||||
def style(self, value):
|
||||
self.obj.CellStyle = value
|
||||
|
||||
def select(self):
|
||||
self.doc.select(self.obj)
|
||||
return
|
||||
|
||||
def search(self, options, find_all=True):
|
||||
rangos = None
|
||||
|
||||
descriptor = self.sheet.search_descriptor
|
||||
descriptor.setSearchString(options['Search'])
|
||||
descriptor.SearchCaseSensitive = options.get('CaseSensitive', False)
|
||||
descriptor.SearchWords = options.get('Words', False)
|
||||
if hasattr(descriptor, 'SearchRegularExpression'):
|
||||
descriptor.SearchRegularExpression = options.get('RegularExpression', False)
|
||||
if hasattr(descriptor, 'SearchType') and 'Type' in options:
|
||||
descriptor.SearchType = options['Type']
|
||||
|
||||
if find_all:
|
||||
found = self.obj.findAll(descriptor)
|
||||
else:
|
||||
found = self.obj.findFirst(descriptor)
|
||||
|
||||
if found:
|
||||
if found.ImplementationName == OBJ_CELL:
|
||||
rangos = LOCalcRange(found)
|
||||
else:
|
||||
rangos = [LOCalcRange(f) for f in found]
|
||||
|
||||
return rangos
|
||||
|
||||
def in_range(self, rango):
|
||||
if isinstance(rango, LOCalcRange):
|
||||
address = rango.range_address
|
||||
|
|
Loading…
Reference in New Issue