Add function zstrip
This commit is contained in:
parent
fd706d59ba
commit
fd4aeef140
|
@ -1,6 +1,5 @@
|
||||||
v 0.2.0 [03-oct-2021]
|
v 0.2.0 [12-jul-2023]
|
||||||
- Add function `zxlookup`
|
- Add function `zstrip`
|
||||||
|
|
||||||
|
|
||||||
v 0.1.0 [27-jun-2021]
|
v 0.1.0 [27-jun-2021]
|
||||||
- Initial version
|
- Initial version
|
||||||
|
|
|
@ -5,8 +5,9 @@ LibreOffice Calc Add-in
|
||||||
|
|
||||||
## Functions
|
## Functions
|
||||||
|
|
||||||
* `zreverse` - Get reverse string
|
* `zreverse` - Get reverse string.
|
||||||
* `zeval` - Parse and execute expresions
|
* `zeval` - Parse and execute expresions.
|
||||||
|
* `zstrip` - Remove extra spaces or characteres. [Look](https://docs.python.org/3/library/stdtypes.html#str.strip)
|
||||||
|
|
||||||
|
|
||||||
![Image](https://git.cuates.net/elmau/zaz-functions/raw/commit/b0e0a93a8ef27523cd3e0e17ec2df1d085881e60/images/image1.png "Functions")
|
![Image](https://git.cuates.net/elmau/zaz-functions/raw/commit/b0e0a93a8ef27523cd3e0e17ec2df1d085881e60/images/image1.png "Functions")
|
||||||
|
|
38
conf.py
38
conf.py
|
@ -142,7 +142,7 @@ FUNCTIONS = {
|
||||||
'parameters': {
|
'parameters': {
|
||||||
'value': {
|
'value': {
|
||||||
'displayname': {'en': 'string', 'es': 'texto'},
|
'displayname': {'en': 'string', 'es': 'texto'},
|
||||||
'description': {'en': 'The string', 'es': 'El cadena'},
|
'description': {'en': 'The string', 'es': 'La cadena'},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -156,33 +156,17 @@ FUNCTIONS = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'zxlookup': {
|
'zstrip': {
|
||||||
'displayname': {'en': 'zxlookup', 'es': 'zbuscarx'},
|
'displayname': {'en': 'zstrip', 'es': 'zstrip'},
|
||||||
'description': {'en': 'Find things in a range by row', 'es': 'Buscar en un rango por fila'},
|
'description': {'en': 'Remove spaces at the beginning and at the end of the string.', 'es': 'Buscar en un rango por fila'},
|
||||||
'parameters': {
|
'parameters': {
|
||||||
'lookup_value': {
|
'value': {
|
||||||
'displayname': {'en': 'lookup_value', 'es': 'valor_buscado'},
|
'displayname': {'en': 'string', 'es': 'texto'},
|
||||||
'description': {'en': 'Value to search', 'es': 'Valor buscado'},
|
'description': {'en': 'Value to trim', 'es': 'Valor a limpiar'},
|
||||||
},
|
},
|
||||||
'lookup_array': {
|
'characters': {
|
||||||
'displayname': {'en': 'lookup_array', 'es': 'buscar_en'},
|
'displayname': {'en': 'characters', 'es': 'caracteres'},
|
||||||
'description': {'en': 'Range to search', 'es': 'Rango en donde buscar'},
|
'description': {'en': 'A set of characters to remove as leading/trailing characters', 'es': 'Caracteres a elmininar de la cadena'},
|
||||||
},
|
|
||||||
'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'},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -239,7 +223,7 @@ URL_OXT = ''
|
||||||
# ~ Default program for test: --calc, --writer, --draw
|
# ~ Default program for test: --calc, --writer, --draw
|
||||||
PROGRAM = '--calc'
|
PROGRAM = '--calc'
|
||||||
# ~ Path to file for test
|
# ~ Path to file for test
|
||||||
FILE_TEST = '/home/mau/test_zfunctions.ods'
|
FILE_TEST = '/home/elmau/Projects/libre_office/examples/zutil_functions.ods'
|
||||||
|
|
||||||
PATHS = {
|
PATHS = {
|
||||||
'idlc': '/usr/lib/libreoffice/sdk/bin/idlc',
|
'idlc': '/usr/lib/libreoffice/sdk/bin/idlc',
|
||||||
|
|
Binary file not shown.
|
@ -26,7 +26,7 @@
|
||||||
</prop>
|
</prop>
|
||||||
<prop oor:name="Description">
|
<prop oor:name="Description">
|
||||||
<value xml:lang="en">The string</value>
|
<value xml:lang="en">The string</value>
|
||||||
<value xml:lang="es">El cadena</value>
|
<value xml:lang="es">La cadena</value>
|
||||||
</prop>
|
</prop>
|
||||||
</node>
|
</node>
|
||||||
</node>
|
</node>
|
||||||
|
@ -57,75 +57,39 @@
|
||||||
</prop>
|
</prop>
|
||||||
</node>
|
</node>
|
||||||
</node>
|
</node>
|
||||||
</node> <node oor:name="zxlookup" oor:op="replace">
|
</node> <node oor:name="zstrip" oor:op="replace">
|
||||||
<prop oor:name="DisplayName">
|
<prop oor:name="DisplayName">
|
||||||
<value xml:lang="en">zxlookup</value>
|
<value xml:lang="en">zstrip</value>
|
||||||
<value xml:lang="es">zbuscarx</value>
|
<value xml:lang="es">zstrip</value>
|
||||||
</prop>
|
</prop>
|
||||||
<prop oor:name="Description">
|
<prop oor:name="Description">
|
||||||
<value xml:lang="en">Find things in a range by row</value>
|
<value xml:lang="en">Remove spaces at the beginning and at the end of the string.</value>
|
||||||
<value xml:lang="es">Buscar en un rango por fila</value>
|
<value xml:lang="es">Buscar en un rango por fila</value>
|
||||||
</prop>
|
</prop>
|
||||||
<prop oor:name="Category">
|
<prop oor:name="Category">
|
||||||
<value>Add-In</value>
|
<value>Add-In</value>
|
||||||
</prop>
|
</prop>
|
||||||
<prop oor:name="CompatibilityName">
|
<prop oor:name="CompatibilityName">
|
||||||
<value xml:lang="en">AutoAddIn.zxlookup</value>
|
<value xml:lang="en">AutoAddIn.zstrip</value>
|
||||||
</prop>
|
</prop>
|
||||||
<node oor:name="Parameters">
|
<node oor:name="Parameters">
|
||||||
<node oor:name="lookup_value" oor:op="replace">
|
<node oor:name="value" oor:op="replace">
|
||||||
<prop oor:name="DisplayName">
|
<prop oor:name="DisplayName">
|
||||||
<value xml:lang="en">lookup_value</value>
|
<value xml:lang="en">string</value>
|
||||||
<value xml:lang="es">valor_buscado</value>
|
<value xml:lang="es">texto</value>
|
||||||
</prop>
|
</prop>
|
||||||
<prop oor:name="Description">
|
<prop oor:name="Description">
|
||||||
<value xml:lang="en">Value to search</value>
|
<value xml:lang="en">Value to trim</value>
|
||||||
<value xml:lang="es">Valor buscado</value>
|
<value xml:lang="es">Valor a limpiar</value>
|
||||||
</prop>
|
</prop>
|
||||||
</node> <node oor:name="lookup_array" oor:op="replace">
|
</node> <node oor:name="characters" oor:op="replace">
|
||||||
<prop oor:name="DisplayName">
|
<prop oor:name="DisplayName">
|
||||||
<value xml:lang="en">lookup_array</value>
|
<value xml:lang="en">characters</value>
|
||||||
<value xml:lang="es">buscar_en</value>
|
<value xml:lang="es">caracteres</value>
|
||||||
</prop>
|
</prop>
|
||||||
<prop oor:name="Description">
|
<prop oor:name="Description">
|
||||||
<value xml:lang="en">Range to search</value>
|
<value xml:lang="en">A set of characters to remove as leading/trailing characters</value>
|
||||||
<value xml:lang="es">Rango en donde buscar</value>
|
<value xml:lang="es">Caracteres a elmininar de la cadena</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>
|
</prop>
|
||||||
</node>
|
</node>
|
||||||
</node>
|
</node>
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#define __net_elmau_zaz_functions_idl__
|
#define __net_elmau_zaz_functions_idl__
|
||||||
|
|
||||||
#include <com/sun/star/uno/XInterface.idl>
|
#include <com/sun/star/uno/XInterface.idl>
|
||||||
#include <com/sun/star/table/XCellRange.idl>
|
|
||||||
|
|
||||||
|
|
||||||
module net { module elmau { module zaz { module functions {
|
module net { module elmau { module zaz { module functions {
|
||||||
|
@ -11,13 +10,7 @@ module net { module elmau { module zaz { module functions {
|
||||||
{
|
{
|
||||||
string zreverse([in] string value);
|
string zreverse([in] string value);
|
||||||
any zeval([in] string value);
|
any zeval([in] string value);
|
||||||
sequence< sequence< any > > zxlookup(
|
string zstrip([in] string value, [in] any characters);
|
||||||
[in] any lookup_value,
|
|
||||||
[in] com::sun::star::table::XCellRange lookup_array,
|
|
||||||
[in] com::sun::star::table::XCellRange return_array,
|
|
||||||
[in] any if_not_found,
|
|
||||||
[in] any match_mode,
|
|
||||||
[in] any search_mode);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
service functions {
|
service functions {
|
||||||
|
|
Binary file not shown.
|
@ -1,4 +1,3 @@
|
||||||
import bisect
|
|
||||||
import uno
|
import uno
|
||||||
import unohelper
|
import unohelper
|
||||||
from net.elmau.zaz.functions import XZAZFunctions
|
from net.elmau.zaz.functions import XZAZFunctions
|
||||||
|
@ -21,50 +20,12 @@ class ZAZFunctions(unohelper.Base, XZAZFunctions):
|
||||||
result = eval(value)
|
result = eval(value)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def zxlookup(self, lookup_value, lookup_array, return_array, if_not_found,
|
def zstrip(self, value, characters=''):
|
||||||
match_mode, search_mode):
|
options = ' '
|
||||||
|
if not characters is None:
|
||||||
# The python default value not set in custom functions
|
options = characters
|
||||||
if match_mode is None:
|
result = value.strip(options)
|
||||||
match_mode = 0
|
return result
|
||||||
if search_mode is None:
|
|
||||||
search_mode = 1
|
|
||||||
|
|
||||||
value = None
|
|
||||||
|
|
||||||
source = lookup_array.DataArray
|
|
||||||
target = return_array.DataArray
|
|
||||||
|
|
||||||
horizontal = False
|
|
||||||
if lookup_array.Columns.Count == 1:
|
|
||||||
source = tuple(map(lambda x: x[0], source))
|
|
||||||
else:
|
|
||||||
horizontal = True
|
|
||||||
source = source[0]
|
|
||||||
target = target[0]
|
|
||||||
|
|
||||||
if search_mode == -1:
|
|
||||||
source = tuple(reversed(source))
|
|
||||||
|
|
||||||
index = next((i for i, v in enumerate(source) if v == lookup_value), None)
|
|
||||||
|
|
||||||
if index is None:
|
|
||||||
if match_mode == -1:
|
|
||||||
index = bisect.bisect_right(source, lookup_value)
|
|
||||||
value = (target[index - 1],)
|
|
||||||
elif match_mode == 1:
|
|
||||||
index = bisect.bisect_left(source, lookup_value)
|
|
||||||
value = (target[index],)
|
|
||||||
else:
|
|
||||||
if horizontal:
|
|
||||||
value = ((target[index],),)
|
|
||||||
else:
|
|
||||||
value = (target[index],)
|
|
||||||
|
|
||||||
if value is None and if_not_found:
|
|
||||||
value = ((if_not_found,),)
|
|
||||||
|
|
||||||
return value
|
|
||||||
|
|
||||||
|
|
||||||
g_ImplementationHelper = unohelper.ImplementationHelper()
|
g_ImplementationHelper = unohelper.ImplementationHelper()
|
||||||
|
|
Loading…
Reference in New Issue