import bisect import uno import unohelper from net.elmau.zaz.functions import XZAZFunctions ID_EXTENSION = 'net.elmau.zaz.functions' SERVICE = ('com.sun.star.sheet.AddIn',) class ZAZFunctions(unohelper.Base, XZAZFunctions): def __init__(self, ctx): self.ctx = ctx def zreverse(self, value): result = value[::-1] return result def zeval(self, value): result = eval(value) return result def zxylookup(self, lookup_value_x, lookup_value_y, return_array, if_not_found): return def zxlookup(self, lookup_value, lookup_array, return_array, if_not_found, match_mode, search_mode): # The python default value not get in custom functions if match_mode is None: match_mode = 0 else: match_mode = int(match_mode) if search_mode is None: search_mode = 1 value = None if len(lookup_array[0]) == 1: source = [r[0] for r in lookup_array] else: source = lookup_array[0] if lookup_value in source: index = source.index(lookup_value) value = (return_array[index],) if value is None: if match_mode == -1: index = bisect.bisect_right(source, lookup_value) value = (return_array[index],) elif match_mode == 1: index = bisect.bisect_left(source, lookup_value) value = (return_array[index],) elif match_mode == 2: pass if value is None and not if_not_found is None: value = ((if_not_found,),) return value g_ImplementationHelper = unohelper.ImplementationHelper() g_ImplementationHelper.addImplementation(ZAZFunctions, ID_EXTENSION, SERVICE)