Skip to content

ICustomFunction usage with python #2

New issue

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

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

Already on GitHub? # to your account

Open
666github666 opened this issue Jan 27, 2023 · 3 comments
Open

ICustomFunction usage with python #2

666github666 opened this issue Jan 27, 2023 · 3 comments

Comments

@666github666
Copy link

Hi, can you share example usage of ICustomFunction implementation?
I have found one example for python via Java but nothing for .NET

@amjad-sahi
Copy link

@666github666,

Please see the document with example code on ICustomFunction feature for your reference. The sample code is in .NET but you may easily convert it to Python. Please note, Aspose.Cells for Python via .NET is very similar to Aspose.Cells for .NET. So, you can refer to the docs.

Should you have further queries or issue, you may also post in dedicated forums.

@666github666
Copy link
Author

666github666 commented Jan 27, 2023

Thanks, I was trying to do that but looks like I'm missing something. Here is my sample class implementation.

`class CustomCalcImpl(ICustomFunction):

def calculate_custom_function(self, function_name, params_list, context_objects):

    a = 4
    b = 4

    return a*b`

And how I use it:
workbook = Workbook("HelloWorld.xlsx") workbook.calculate_formula(False, CustomCalcImpl())

But get error:

class CustomCalcImpl(ICustomFunction): TypeError: type 'aspose.cells.ICustomFunction' is not an acceptable base type

Whole code:

`
from aspose.cells import Workbook, ICustomFunction

class CustomCalcImpl(ICustomFunction):

def calculate_custom_function(self, function_name, params_list, context_objects):

    a = 4
    b = 4

    return a*b

if name == 'main':

workbook = Workbook()
workbook.calculate_formula(False, CustomCalcImpl())`

@amjad-sahi
Copy link

Please import and implement ICustomFunction at the start of your program. Please do it properly and accordingly in your code for Python via .NET.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants