ajCustomFunction function
Description
The ajCustomFunction function executes a native Java class method at runtime.
Please take note that the AlchemyJ Studio in Microsoft Excel is not able to trigger and run the Java class method after pressing Preview Function Point. However, you can create a macro that simulates the corresponding return result of the Java method in VBA.
Syntax
ajCustomFunction(class_name, is_instance, constructor_parameter, method_name, method_parameter, [run_condition], [run_by_function_point_only])
Argument Name | Argument Type | Description |
---|---|---|
class_name (required) | String | The Java class name, e.g. com.axisoft.alchemyj.test.ajCustomFunctionExample. If using the simulation program generated by Microsoft Excel macro, specify the module name of Microsoft Excel macro. |
is_instance (required) | Boolean | Whether the call should be executed as an instance call or a static call. - If is_instance is TRUE, AJ calls the custom function as an instance call. - If is_instance is FALSE, AJ calls the custom function as a static call. |
constructor_parameter (required) | Range / Array | The parameters to be keyed into the method constructor. Refer to the Function Parameters Snippet to see how to use this snippet to define the required fields. |
method_name (required) | String | The method name in the class to be called. Please take note that it is also the function name in the Microsoft Excel macro. |
method_parameter (required) | Range / Array | The parameters to be keyed into the method . Refer to the Function Parameters Snippet to see how to use this snippet to define the required fields. |
run_condition (optional) | Boolean | The function will run when the value is TRUE. Otherwise, it will not run. The default value is TRUE. |
run_by_function_point_only (optional) | Boolean | If it equals FALSE, the function can be executed through ‘Excel Calculation’ (can be either Automatic or Manual, Calculate Now or Calculate Sheet) or Preview Function Point. If it equals TRUE, the function can be executed with Preview Function Point (AlchemyJ ribbon \ Preview Function Point) only. The default value is TRUE. |
The function will return:
1) Return Value: The result of the Java or Excel macro function
2) Return Type: Single Value
Example using Excel macro simulation program
As you can see from the above example, ajCustomFunction is successful and the result of the macro is returned. Otherwise, it will return #VALUE!.
Please take note that AlchemyJ will not compile the macro into JAR/WAR when building the project. This function in Microsoft Excel acts as a simulator that calls the other Java class at runtime.
The external Java program cannot be executed in AlchemyJ workbook. Refer to Calling External Java Function recipe book for how to configure the Java External Program.
Error Scenarios
It will return #VALUE! when missing any required parameter or mismatch parameter type. Besides, system will raise error for below scenario(s).
Error Scenario |
---|
Failed to call the Java method. |
Invalid method parameter format. |
Invalid constructor parameter format. |