Add function zxlookup
This commit is contained in:
parent
a4d1a790e0
commit
8c69515f06
|
@ -1,4 +1,8 @@
|
|||
v 0.2.0 [03-oct-2021]
|
||||
- Add function `zxlookup`
|
||||
|
||||
|
||||
v 0.1.0 [27-jun-2021]
|
||||
- Initial version
|
||||
- Function `reverse`
|
||||
- Function `eval`
|
||||
- Function `zreverse`
|
||||
- Function `zeval`
|
||||
|
|
64
conf.py
64
conf.py
|
@ -29,7 +29,7 @@ TYPE_EXTENSION = 3
|
|||
NAME = 'ZAZFunctions'
|
||||
|
||||
# ~ https://semver.org/
|
||||
VERSION = '0.1.0'
|
||||
VERSION = '0.2.0'
|
||||
|
||||
|
||||
# ~ Should be unique, used URL inverse
|
||||
|
@ -80,13 +80,13 @@ LICENSE_ES = LICENSE_EN
|
|||
|
||||
INFO = {
|
||||
'en': {
|
||||
'display_name': 'My first extension',
|
||||
'description': 'My great extension',
|
||||
'display_name': 'ZAZ Functions',
|
||||
'description': 'Utils functions for Calc',
|
||||
'license': LICENSE_EN,
|
||||
},
|
||||
'es': {
|
||||
'display_name': 'Mi primer extensión',
|
||||
'description': 'Mi gran extensión',
|
||||
'display_name': 'ZAZ Funciones',
|
||||
'description': 'Funciones utiles para Calc',
|
||||
'license': LICENSE_ES,
|
||||
},
|
||||
}
|
||||
|
@ -156,6 +156,56 @@ FUNCTIONS = {
|
|||
},
|
||||
},
|
||||
},
|
||||
'zxlookup': {
|
||||
'displayname': {'en': 'zxlookup', 'es': 'zbuscarx'},
|
||||
'description': {'en': 'Find things in a range by row', 'es': 'Buscar en un rango por fila'},
|
||||
'parameters': {
|
||||
'lookup_value': {
|
||||
'displayname': {'en': 'lookup_value', 'es': 'valor_buscado'},
|
||||
'description': {'en': 'Value to search', 'es': 'Valor buscado'},
|
||||
},
|
||||
'lookup_array': {
|
||||
'displayname': {'en': 'lookup_array', 'es': 'buscar_en'},
|
||||
'description': {'en': 'Range to search', 'es': 'Rango en donde buscar'},
|
||||
},
|
||||
'return_array': {
|
||||
'displayname': {'en': 'return_array', 'es': 'devolver_desde'},
|
||||
'description': {'en': 'Range to return', 'es': 'Rango a devolver'},
|
||||
},
|
||||
'if_not_found': {
|
||||
'displayname': {'en': 'if_not_found', 'es': 'si_no_se_encuentra'},
|
||||
'description': {'en': 'Return if not found', 'es': 'Valor devuelto si no se encuentra'},
|
||||
},
|
||||
'match_mode': {
|
||||
'displayname': {'en': 'match_mode', 'es': 'tipo_busqueda'},
|
||||
'description': {'en': 'The macht type', 'es': 'El tipo de búsqueda'},
|
||||
},
|
||||
'search_mode': {
|
||||
'displayname': {'en': 'search_mode', 'es': 'mode_de_busqueda'},
|
||||
'description': {'en': 'The search mode', 'es': 'El modo de búsqueda'},
|
||||
},
|
||||
},
|
||||
},
|
||||
'zxylookup': {
|
||||
'displayname': {'en': 'zxylookup', 'es': 'zbuscarxy'},
|
||||
'description': {
|
||||
'en': 'Find things in a range in first row and first column, get intersection',
|
||||
'es': 'Busca en un rango en la primer fila y columna y devuelve la intersección'},
|
||||
'parameters': {
|
||||
'lookup_value_x': {
|
||||
'displayname': {'en': 'lookup_value_x', 'es': 'valor_buscado_x'},
|
||||
'description': {'en': 'Value to search in first row', 'es': 'Valor buscado en la primer fila'},
|
||||
},
|
||||
'lookup_value_y': {
|
||||
'displayname': {'en': 'lookup_value_y', 'es': 'valor_buscado_y'},
|
||||
'description': {'en': 'Value to search in first column', 'es': 'Valor buscado en la primer columna'},
|
||||
},
|
||||
'return_array': {
|
||||
'displayname': {'en': 'return_array', 'es': 'devolver_desde'},
|
||||
'description': {'en': 'Range to return', 'es': 'Rango a devolver'},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
# ~ FUNCTIONS = {}
|
||||
|
||||
|
@ -176,7 +226,7 @@ DIRS = {
|
|||
'description': 'description',
|
||||
'images': 'images',
|
||||
'registration': 'registration',
|
||||
'files': 'files',
|
||||
'files': 'extension',
|
||||
'office': 'Office',
|
||||
'locales': PATH_LOCALES,
|
||||
'pythonpath': True,
|
||||
|
@ -209,7 +259,7 @@ URL_OXT = ''
|
|||
# ~ Default program for test: --calc, --writer, --draw
|
||||
PROGRAM = '--calc'
|
||||
# ~ Path to file for test
|
||||
FILE_TEST = ''
|
||||
FILE_TEST = '/home/mau/test_zfunctions.ods'
|
||||
|
||||
PATHS = {
|
||||
'idlc': '/usr/lib/libreoffice/sdk/bin/idlc',
|
||||
|
|
Binary file not shown.
|
@ -57,6 +57,123 @@
|
|||
</prop>
|
||||
</node>
|
||||
</node>
|
||||
</node> <node oor:name="zxlookup" oor:op="replace">
|
||||
<prop oor:name="DisplayName">
|
||||
<value xml:lang="en">zxlookup</value>
|
||||
<value xml:lang="es">zbuscarx</value>
|
||||
</prop>
|
||||
<prop oor:name="Description">
|
||||
<value xml:lang="en">Find things in a range by row</value>
|
||||
<value xml:lang="es">Buscar en un rango por fila</value>
|
||||
</prop>
|
||||
<prop oor:name="Category">
|
||||
<value>Add-In</value>
|
||||
</prop>
|
||||
<prop oor:name="CompatibilityName">
|
||||
<value xml:lang="en">AutoAddIn.zxlookup</value>
|
||||
</prop>
|
||||
<node oor:name="Parameters">
|
||||
<node oor:name="lookup_value" oor:op="replace">
|
||||
<prop oor:name="DisplayName">
|
||||
<value xml:lang="en">lookup_value</value>
|
||||
<value xml:lang="es">valor_buscado</value>
|
||||
</prop>
|
||||
<prop oor:name="Description">
|
||||
<value xml:lang="en">Value to search</value>
|
||||
<value xml:lang="es">Valor buscado</value>
|
||||
</prop>
|
||||
</node> <node oor:name="lookup_array" oor:op="replace">
|
||||
<prop oor:name="DisplayName">
|
||||
<value xml:lang="en">lookup_array</value>
|
||||
<value xml:lang="es">buscar_en</value>
|
||||
</prop>
|
||||
<prop oor:name="Description">
|
||||
<value xml:lang="en">Range to search</value>
|
||||
<value xml:lang="es">Rango en donde buscar</value>
|
||||
</prop>
|
||||
</node> <node oor:name="return_array" oor:op="replace">
|
||||
<prop oor:name="DisplayName">
|
||||
<value xml:lang="en">return_array</value>
|
||||
<value xml:lang="es">devolver_desde</value>
|
||||
</prop>
|
||||
<prop oor:name="Description">
|
||||
<value xml:lang="en">Range to return</value>
|
||||
<value xml:lang="es">Rango a devolver</value>
|
||||
</prop>
|
||||
</node> <node oor:name="if_not_found" oor:op="replace">
|
||||
<prop oor:name="DisplayName">
|
||||
<value xml:lang="en">if_not_found</value>
|
||||
<value xml:lang="es">si_no_se_encuentra</value>
|
||||
</prop>
|
||||
<prop oor:name="Description">
|
||||
<value xml:lang="en">Return if not found</value>
|
||||
<value xml:lang="es">Valor devuelto si no se encuentra</value>
|
||||
</prop>
|
||||
</node> <node oor:name="match_mode" oor:op="replace">
|
||||
<prop oor:name="DisplayName">
|
||||
<value xml:lang="en">match_mode</value>
|
||||
<value xml:lang="es">tipo_busqueda</value>
|
||||
</prop>
|
||||
<prop oor:name="Description">
|
||||
<value xml:lang="en">The macht type</value>
|
||||
<value xml:lang="es">El tipo de búsqueda</value>
|
||||
</prop>
|
||||
</node> <node oor:name="search_mode" oor:op="replace">
|
||||
<prop oor:name="DisplayName">
|
||||
<value xml:lang="en">search_mode</value>
|
||||
<value xml:lang="es">mode_de_busqueda</value>
|
||||
</prop>
|
||||
<prop oor:name="Description">
|
||||
<value xml:lang="en">The search mode</value>
|
||||
<value xml:lang="es">El modo de búsqueda</value>
|
||||
</prop>
|
||||
</node>
|
||||
</node>
|
||||
</node> <node oor:name="zxylookup" oor:op="replace">
|
||||
<prop oor:name="DisplayName">
|
||||
<value xml:lang="en">zxylookup</value>
|
||||
<value xml:lang="es">zbuscarxy</value>
|
||||
</prop>
|
||||
<prop oor:name="Description">
|
||||
<value xml:lang="en">Find things in a range in first row and first column, get intersection</value>
|
||||
<value xml:lang="es">Busca en un rango en la primer fila y columna y devuelve la intersección</value>
|
||||
</prop>
|
||||
<prop oor:name="Category">
|
||||
<value>Add-In</value>
|
||||
</prop>
|
||||
<prop oor:name="CompatibilityName">
|
||||
<value xml:lang="en">AutoAddIn.zxylookup</value>
|
||||
</prop>
|
||||
<node oor:name="Parameters">
|
||||
<node oor:name="lookup_value_x" oor:op="replace">
|
||||
<prop oor:name="DisplayName">
|
||||
<value xml:lang="en">lookup_value_x</value>
|
||||
<value xml:lang="es">valor_buscado_x</value>
|
||||
</prop>
|
||||
<prop oor:name="Description">
|
||||
<value xml:lang="en">Value to search in first row</value>
|
||||
<value xml:lang="es">Valor buscado en la primer fila</value>
|
||||
</prop>
|
||||
</node> <node oor:name="lookup_value_y" oor:op="replace">
|
||||
<prop oor:name="DisplayName">
|
||||
<value xml:lang="en">lookup_value_y</value>
|
||||
<value xml:lang="es">valor_buscado_y</value>
|
||||
</prop>
|
||||
<prop oor:name="Description">
|
||||
<value xml:lang="en">Value to search in first column</value>
|
||||
<value xml:lang="es">Valor buscado en la primer columna</value>
|
||||
</prop>
|
||||
</node> <node oor:name="return_array" oor:op="replace">
|
||||
<prop oor:name="DisplayName">
|
||||
<value xml:lang="en">return_array</value>
|
||||
<value xml:lang="es">devolver_desde</value>
|
||||
</prop>
|
||||
<prop oor:name="Description">
|
||||
<value xml:lang="en">Range to return</value>
|
||||
<value xml:lang="es">Rango a devolver</value>
|
||||
</prop>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
|
|
|
@ -9,6 +9,18 @@ module net { module elmau { module zaz { module functions {
|
|||
{
|
||||
string zreverse([in] string value);
|
||||
any zeval([in] string value);
|
||||
sequence< sequence< any > > zxlookup(
|
||||
[in] any lookup_value,
|
||||
[in] any lookup_array,
|
||||
[in] any return_array,
|
||||
[in] any if_not_found,
|
||||
[in] any match_mode,
|
||||
[in] any search_mode);
|
||||
any zxylookup(
|
||||
[in] any lookup_value_x,
|
||||
[in] any lookup_value_y,
|
||||
[in] any return_array,
|
||||
[in] any if_not_found);
|
||||
};
|
||||
|
||||
service functions {
|
||||
|
|
Binary file not shown.
|
@ -1,3 +1,4 @@
|
|||
import bisect
|
||||
import uno
|
||||
import unohelper
|
||||
from net.elmau.zaz.functions import XZAZFunctions
|
||||
|
@ -20,6 +21,46 @@ class ZAZFunctions(unohelper.Base, XZAZFunctions):
|
|||
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)
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<description xmlns="http://openoffice.org/extensions/description/2006" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:d="http://openoffice.org/extensions/description/2006">
|
||||
<identifier value="net.elmau.zaz.functions"/>
|
||||
<version value="0.1.0"/>
|
||||
<version value="0.2.0"/>
|
||||
<display-name>
|
||||
<name lang="en">My first extension</name>
|
||||
<name lang="es">Mi primer extensión</name>
|
||||
<name lang="en">ZAZ Functions</name>
|
||||
<name lang="es">ZAZ Funciones</name>
|
||||
</display-name>
|
||||
<extension-description>
|
||||
<src lang="en" xlink:href="description/desc_en.txt"/>
|
||||
|
|
|
@ -1 +1 @@
|
|||
My great extension
|
||||
Utils functions for Calc
|
|
@ -1 +1 @@
|
|||
Mi gran extensión
|
||||
Funciones utiles para Calc
|
Loading…
Reference in New Issue