Skip to content

Commit

Permalink
lifted get_category out of xlfunc
Browse files Browse the repository at this point in the history
  • Loading branch information
fzumstein committed Jan 14, 2017
1 parent 64ff5f5 commit 7c09f41
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions xlwings/udfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,24 @@ def func_sig(f):
}


def get_category(**func_kwargs):
if 'category' in func_kwargs:
category = func_kwargs.pop('category')
if isinstance(category, int):
if 1 <= category <= 14:
return category
raise Exception(
'There is only 14 build-in categories available in Excel. Please use a string value to specify a custom category.')
if isinstance(category, str):
return category[:255]
raise Exception(
'Category {0} should either be a predefined Excel category (int value) or a custom one (str value).'.format(
category))
return 14 # Default category is "User Defined"


def xlfunc(f=None, **kwargs):
def inner(f):
def get_category(**func_kwargs):
if 'category' in func_kwargs:
category = func_kwargs.pop('category')
if isinstance(category, int):
if 1 <= category <= 14:
return category
raise Exception('There is only 14 build-in categories available in Excel. Please use a string value to specify a custom category.')
if isinstance(category, str):
return category[:255]
raise Exception('Category {0} should either be a predefined Excel category (int value) or a custom one (str value).'.format(category))
return 14 # Default category is "User Defined"

if not hasattr(f, "__xlfunc__"):
xlf = f.__xlfunc__ = {}
xlf["name"] = f.__name__
Expand Down

0 comments on commit 7c09f41

Please sign in to comment.