Calculate Excel Formulas and Implement Custom or User Defined Functions in C++

create user defined function in excel

Aspose Team is pleased to announce the release of Aspose.Cells for C++ 17.02.0. This release includes some new features and enhancements that further improve the overall feature set of the API. Please check the release notes in order to get an idea about what is new and what has been enhanced with this revision of Aspose.Cells for C++. If you are planning to upgrade the API from any previous version, we strongly suggest you to check the Public API Changes section to know what has been changed since your current revision of the API.

While you are downloading the API build to give it a try, here is a list of added features along with some code snippets for quick testing.

Improvements and Flexibility in the Calculation of Excel Formulas

Aspose.Cells for C++ has added more overloads of workbook calculation which provide users more control and flexibility to calculate the excel functions on runtime. Users can also implement their own custom functions if needed.

Different Ways to Calculate Formulas

There are different ways to calculate excel formulas on runtime using Aspose.Cells for C++.  Please check the following article that explains all of them with sample code.

Here are these three different ways to calculate excel formulas on runtime using the Aspose.Cells for C++.

  • Adding Formulas and Calculating Results
  • Direct Calculation of Formula
  • Calculating Formulas Once Only

Implement Custom Functions with Aspose.Cells

Aspose.Cells for C++ now supports ICustomFunction interface that allows you to define custom (i.e. user defined) functions in a template file or in a code where the custom function can be implemented and evaluated using Aspose.Cells APIs like any other default Microsoft Excel function. Please see the following article that explains how to make use of this feature

Here is the simplest implementation of ICustomFunction interface in Aspose.Cells for C++.

//Implement ICustomFunction interface
class CustomFunction : public ICustomFunction
{
public:
    //Evalaute and return the values of your custom functions
    intrusive_ptr 
        CalculateCustomFunction(
        intrusive_ptr functionName, 
        intrusive_ptr paramsList, 
        intrusive_ptr contextObjects)
    {
            if (functionName->Equals(new String("MySampleFunc")))
            {
                return new String("MY sample function was called successfully.");
            }
 
            if (functionName->Equals(new String("YourSampleFunc")))
            {
                return new String("YOUR sample function was called successfully.");
            }
 
            return NULL;
    }
 
};

Aspose.Cells for C++ Resources

The resources, you may need to accomplish your tasks:

Keeping the Aspose tradition, you are welcome to shape the upcoming releases of Aspose.Cells for C++ API by posting your suggestions and concerns in the Aspose.Cells support forum.