XLL+ Class Library

MySort Example

This example demonstrates how to transform Excel data to an STL vector and back again.

// Function:    MySort
// Returns:     LPXLOPER
// Description: Sort a vector of numeric values

#include <vector>
#include <algorithm>
using namespace std;

//{{XLP_SRC(MySort)
    // NOTE - the FunctionWizard will add and remove mapping code here.
    //    DO NOT EDIT what you see in these blocks of generated code!
IMPLEMENT_XLLFN2(MySort, "RP", "MySort", "Input", "User Defined",
    "Sort a vector of numeric values", "Numeric vector\000", "\0"
    , 1)

extern "C" __declspec( dllexport )
LPXLOPER MySort(const COper* lpopInput)
{
    CXlOper xloResult;
//}}XLP_SRC

    vector<double> vecInput;
    CString strError;
    BOOL bOk = TRUE;

    if ( !(bOk = lpopInput->ColToVector(vecInput, &strError)) )
        xloResult = "Error in Input: " + strError;

    if ( bOk ) 
    {
        sort(vecInput.begin(), vecInput.end());
        xloResult = vecInput;
    }
    return xloResult.Ret();
}

Uses

COper::ColToVector | CXlOper::operator =