Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to properly use the excel_helper decorator? #138

Open
igheorghita opened this issue Nov 14, 2021 · 0 comments
Open

How to properly use the excel_helper decorator? #138

igheorghita opened this issue Nov 14, 2021 · 0 comments

Comments

@igheorghita
Copy link
Contributor

What actually happened and expected behavior

Sorry, this is probably more a question than an issue, but I'm trying to use the excel_helper decorator and it's not behaving the way I would have expected, so I'm wondering if I've misunderstood the purpose of it. For example, I wanted to write a columns function. My first idea was to do something along the lines of (ignoring edge cases here):

@excel_helper(ref_params=0)
def columns(ref):
    # Excel reference: https://support.microsoft.com/en-us/office/
    #   columns-function-4e8e7b4e-e603-43e8-b177-956088fa48ca
    if ref.is_range:
        return ref.end.col_idx - ref.start.col_idx

I would have expected the decorator to force the argument to be an AddressCell or AddressRange, but it doesn't seem to do anything. For example, if I do something like:

from openpyxl import Workbook
wb = Workbook()
ws = wb.active
ws['E1'] = '=COLUMNS(A1:C1)'

from pycel.excelcompiler import ExcelCompiler
model = ExcelCompiler(excel=wb)
model.evaluate('Sheet!E1')

I see that when the model tries to evaluate 'E1', the ref argument is (None, None, None) and not the AddressRange I expected. Is there somewhere else in the code where I need to indicate that I expected the columns function to accept references? Or is there a reason why this shouldn't be done?

I noticed that with the column function, even if I remove the excel_helper decorator, it still parses the input as an AddressCell, which makes me think I've misunderstood the point of the decorator.

We can define the columns function with something like this instead, but I thought the reference way would be cleaner:

def columns(value):
    return len(value[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant