Tham khảo tài liệu 'excel add-in development in c/c++ applications in finance phần 6', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Accessing Excel Functionality Using the C API 179 The following example simply provides a worksheet interface to Excel4v allowing the function number and the arguments that are appropriate for that function to be passed in directly from the sheet. This can be an extremely useful tool but also one to be used with great care. This section outlines some of the things this enables you to do but first here s the code with comments that explain what is going on. xloper __stdcall XL4 int xlfn xloper arg0 xloper arg1 xloper arg2 xloper arg3 xloper arg4 xloper arg5 xloper arg6 xloper arg7 xloper arg8 xloper arg9 xloper arg10 xloper arg11 xloper arg12 xloper arg13 xloper arg14 xloper arg15 xloper arg16 xloper arg17 xloper arg18 xloper arg_array 19 static xloper ret_xloper Fill in array of pointers to the xloper arguments ready for the call to Excel4v arg_array 0 arg0 arg_array 1 arg1 arg_array 2 arg2 arg_array 3 arg3 arg_array 4 arg4 arg_array 5 arg5 arg_array 6 arg6 arg_array 7 arg7 arg_array 8 arg8 arg_array 9 arg9 arg_array 10 arg10 arg_array 11 arg11 arg_array 12 arg12 arg_array 13 arg13 arg_array 14 arg14 arg_array 15 arg15 arg_array 16 arg16 arg_array 17 arg17 arg_array 18 arg18 Find the last non-missing argument for int i 19 --i 0 if arg_array i - xltype xltypeMissing break Call the function int retval Excel4v xlfn ret_xloper i 1 arg_array if retval xlretSuccess If the call to Excel4v failed return a string explaining why and tell Excel to call back into the DLL to free the memory about to be allocated for the return string. xltypeStr xlbitDLLFree new_xlstring Excel4_err_msg retval else Tell Excel to free up memory that it might have allocated for 180 Excel Add-in Development in C C the return value. xlbitXLFree return ret_xloper The function Excel4_err_msg simply returns a string with an appropriate error message should the call to Excel4v fail and is listed below. The function new_xlstring creates a byte-counted