Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_ref_wrap(value, result):
def r_test(*args):
return args
name_space = locals()
name_space['_R_'] = lambda a: 'R:{}'.format(a)
name_space['_C_'] = lambda a: 'C:{}'.format(a)
func = apply_meta(
excel_helper(ref_params=1)(r_test), name_space=name_space)[0]
assert func(*value) == result
@excel_helper(cse_params=0)
def isodd(value):
# Excel reference: https://support.office.com/en-us/article/
# is-functions-0f2d7971-6019-40a0-a171-f2d869135665
if isinstance(value, bool):
return VALUE_ERROR
value = coerce_to_number(value)
if isinstance(value, str):
return VALUE_ERROR
return bool(math.floor(abs(value)) % 2)
@excel_helper(cse_params=0)
def lookup(lookup_value, lookup_array, result_range=None):
"""
There are two ways to use LOOKUP: Vector form and Array form
Vector form: lookup_array is list like (ie: n x 1)
Array form: lookup_array is rectangular (ie: n x m)
First row or column is the lookup vector.
Last row or column is the result vector
The longer dimension is the search dimension
:param lookup_value: value to match (value or cell reference)
:param lookup_array: range of cells being searched.
:param result_range: (optional vector form) values are returned from here
:return: #N/A if not found else value
@excel_helper(cse_params=0, err_str_params=None)
def istext(arg):
# Excel reference: https://support.office.com/en-us/article/
# is-functions-0f2d7971-6019-40a0-a171-f2d869135665
return isinstance(arg, str) and arg not in ERROR_CODES
@excel_helper(cse_params=0, err_str_params=None)
def isnumber(value):
# Excel reference: https://support.office.com/en-us/article/
# is-functions-0f2d7971-6019-40a0-a171-f2d869135665
return isinstance(value, (int, float))
@excel_helper(err_str_params=-1)
def edate(start_date, months):
# Excel reference: https://support.office.com/en-us/article/
# edate-function-3c920eb2-6e66-44e7-a1f5-753ae47ee4f5
return months_inc(start_date, months)
@excel_helper(cse_params=0, bool_params=3, number_params=2)
def vlookup(lookup_value, table_array, col_index_num, range_lookup=True):
""" Vertical Lookup
:param lookup_value: value to match (value or cell reference)
:param table_array: range of cells being searched.
:param col_index_num: column number to return
:param range_lookup: True, assumes sorted, finds nearest. False: find exact
:return: #N/A if not found else value
"""
# Excel reference: https://support.office.com/en-us/article/
# VLOOKUP-function-0BBC8083-26FE-4963-8AB8-93A18AD188A1
if not list_like(table_array):
return NA_ERROR
if col_index_num <= 0:
@excel_helper(cse_params=0, number_params=(1, 2))
def replace(old_text, start_num, num_chars, new_text):
# Excel reference: https://support.office.com/en-us/article/
# replace-replaceb-functions-8d799074-2425-4a8a-84bc-82472868878a
old_text = coerce_to_string(old_text)
new_text = coerce_to_string(new_text)
start_num = int(start_num) - 1
num_chars = int(num_chars)
if start_num < 0 or num_chars < 0:
return VALUE_ERROR
return '{}{}{}'.format(
old_text[:start_num], new_text, old_text[start_num + num_chars:])
@excel_helper(cse_params=0)
def trim(text):
# Excel reference: https://support.office.com/en-us/article/
# trim-function-410388fa-c5df-49c6-b16c-9e5630b479f9
return RE_MULTI_SPACE.sub(' ', coerce_to_string(text))
@excel_helper(cse_params=0)
def upper(text):
# Excel reference: https://support.office.com/en-us/article/
# upper-function-c11f29b3-d1a3-4537-8df6-04d0049963d6
return coerce_to_string(text).upper()