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