XLL+ Class Library (6.3)

CXlOper::Excel() Example

This example demonstrates a call to the Excel SDK. It uses the xlfDate function to calculate a date in Excel format from a year, month and day.

CopyC++
//{{XLP_SRC(GetDate) 
    // NOTE - the FunctionWizard will add and remove mapping code here. 
    //    DO NOT EDIT what you see in these blocks of generated code!
IMPLEMENT_XLLFN3(GetDate, GetDate_4, GetDate_12, "R", "U", L"GetDate", 0, L"", 
    0, L"Demo functions", 0, L"Returns a date calculated by a call-back to Exc"
    L"el", 0, L"", 0, 0, L"{GetDate,,,Returns a date calculated by a call-back"
    L" to Excel,Demo functions,1,128,U,{},{},3,,0,0}", 1)
CXlOper* GetDate_Impl(CXlOper&);

extern "C" __declspec(dllexport)
LPXLOPER12 GetDate_12()
{
    XLL_FIX_STATE;
    CXlOper xloResult;
    try {
        CXlStructuredExceptionHandler _seh_;
        xloResult.HandleResult(GetDate_Impl(xloResult));
    }
    catch(const CXlRuntimeException& ex) {
        CXllApp::Instance()->DisplayException(xloResult, ex);
    }
    return xloResult.Ret12();
}
extern "C" __declspec(dllexport)
LPXLOPER4 GetDate_4()
{
    XLL_FIX_STATE;
    CXlOper xloResult;
    try {
        CXlStructuredExceptionHandler _seh_;
        xloResult.HandleResult(GetDate_Impl(xloResult));
    }
    catch(const CXlRuntimeException& ex) {
        CXllApp::Instance()->DisplayException(xloResult, ex);
    }
    return xloResult.Ret4();
}

CXlOper* GetDate_Impl(CXlOper& xloResult)
{
    // End of generated code 
//}}XLP_SRC 
 
    static int xlfDate = 65;

    CXlOper xloYear(97.0), xloMonth(12.0), xloDay(31.0);
    CXlOper xloDate;

    if (!xloDate.Excel(xlfDate, 3, &xloYear, &xloMonth, &xloDay))
        xloResult = xloDate;
    else
        xloResult = xlerrNA;
    return xloResult.Ret();
}

Uses

CXlOper::Excel