XLL+ Class Library (7.0)

CXlOper::AllocArray() Example

CopyC++
//{{XLP_SRC(AllocArrayEx) 
    // NOTE - the FunctionWizard will add and remove mapping code here. 
    //    DO NOT EDIT what you see in these blocks of generated code! 
 
#pragma region AllocArrayEx support code
IMPLEMENT_XLLFN4(AllocArrayEx, AllocArrayEx_4, AllocArrayEx_12, "R", "U", L"Al"
    L"locArrayEx", 0, L"", 0, L"Demo functions", 0, L"Returns a mixed array of"
    L" data", 0, L"", 0, 0, L"{AllocArrayEx,,,Returns a mixed array of data,De"
    L"mo functions,1,128,U,{},{},3,,0,0,,,,0,0}", 1, 0, 0)
CXlOper* AllocArrayEx_Impl(CXlOper&);
extern "C" __declspec(dllexport)
LPXLOPER12 AllocArrayEx_12()
{
    XLL_FIX_STATE;
    CXlOper xloResult;
    try {
        CXlStructuredExceptionHandler _seh_;
        xloResult.HandleResult(AllocArrayEx_Impl(xloResult));
    }
    catch(const CXlRuntimeException& ex) {
        CXllApp::Instance()->DisplayException(xloResult, ex);
    }
    XLP_CATCH_CLR_EXCEPTIONS_TO(xloResult)
    return xloResult.Ret12();
}
extern "C" __declspec(dllexport)
LPXLOPER4 AllocArrayEx_4()
{
    XLL_FIX_STATE;
    CXlOper xloResult;
    try {
        CXlStructuredExceptionHandler _seh_;
        xloResult.HandleResult(AllocArrayEx_Impl(xloResult));
    }
    catch(const CXlRuntimeException& ex) {
        CXllApp::Instance()->DisplayException(xloResult, ex);
    }
    XLP_CATCH_CLR_EXCEPTIONS_TO(xloResult)
    return xloResult.Ret4();
}

#pragma endregion

CXlOper* AllocArrayEx_Impl(CXlOper& xloResult)
{
    // End of generated code 
//}}XLP_SRC 
 
    // Allocate an array of empty cells
    USHORT cRows = 3, cCols = 2;
    xloResult.AllocArray(cRows, cCols);

    // Set each cell 
    for (USHORT i = 0; i < cRows; i++) {
        // Put a number in the first cell
        xloResult.Cell(i, 0) = (double)i;
        // Put a string in the second cell
        CString strFormat;
        strFormat.Format("String %d", i);
        xloResult.Cell(i, 1) = strFormat;
    }

    // Return the array to Excel 
    return xloResult.Ret();
}

Uses

CXlOper::AllocArray | CXlOper::Format | CXlOper::Cell