Ejemplo n.º 1
0
def find(find_text, within_text, start_num=1):
    # Excel reference: https://support.office.com/en-us/article/
    #   FIND-FINDB-functions-C7912941-AF2A-4BDF-A553-D0D89B0A0628
    find_text = coerce_to_string(find_text)
    within_text = coerce_to_string(within_text)
    found = within_text.find(find_text, start_num - 1)
    if found == -1:
        return VALUE_ERROR
    else:
        return found + 1
Ejemplo n.º 2
0
def find(find_text, within_text, start_num=1):
    # Excel reference: https://support.office.com/en-us/article/
    #   FIND-FINDB-functions-C7912941-AF2A-4BDF-A553-D0D89B0A0628
    find_text = coerce_to_string(find_text)
    within_text = coerce_to_string(within_text)
    found = within_text.find(find_text, start_num - 1)
    if found == -1:
        return VALUE_ERROR
    else:
        return found + 1
Ejemplo n.º 3
0
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:])
Ejemplo n.º 4
0
    def wrapper(*args):
        new_args = tuple(
            coerce_to_string(a) if i in param_indices else a
            for i, a in enumerate(args))
        error = next((a for i, a in enumerate(new_args)
                      if i in param_indices and a in ERROR_CODES), None)
        if error:
            return error

        return f(*new_args)
Ejemplo n.º 5
0
def concatenate(*args):
    # Excel reference: https://support.office.com/en-us/article/
    #   CONCATENATE-function-8F8AE884-2CA8-4F7A-B093-75D702BEA31D
    if tuple(flatten(args)) != args:
        return VALUE_ERROR

    error = next((x for x in args if x in ERROR_CODES), None)
    if error:
        return error

    return ''.join(coerce_to_string(a) for a in args)
Ejemplo n.º 6
0
def concatenate(*args):
    # Excel reference: https://support.office.com/en-us/article/
    #   CONCATENATE-function-8F8AE884-2CA8-4F7A-B093-75D702BEA31D
    if tuple(flatten(args)) != args:
        return VALUE_ERROR

    error = next((x for x in args if x in ERROR_CODES), None)
    if error:
        return error

    return ''.join(coerce_to_string(a) for a in args)
Ejemplo n.º 7
0
def test_coerce_to_string(value, result):
    assert coerce_to_string(value) == result
Ejemplo n.º 8
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()
Ejemplo n.º 9
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))
Ejemplo n.º 10
0
def lower(text):
    # Excel reference: https://support.office.com/en-us/article/
    #   lower-function-3f21df02-a80c-44b2-afaf-81358f9fdeb4
    return coerce_to_string(text).lower()
Ejemplo n.º 11
0
def test_coerce_to_string(value, expected):
    assert coerce_to_string(value) == expected
Ejemplo n.º 12
0
def test_coerce_to_string(value, result):
    assert coerce_to_string(value) == result