XLL+ Class Library (6.3)

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!
IMPLEMENT_XLLFN3(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}", 1)
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);
    }
    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);
    }
    return xloResult.Ret4();
}

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