XLL+ Class Library (6.3)

MySort Example

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

CopyC++
// 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_XLLFN3(MySort, MySort_4, MySort_12, "RP", "UQ", L"MySort", 0, L"Inpu"
    L"t", 0, L"14", 0, L"Sort a vector of numeric values", 0, L"Numeric vector"
    L"\0", 0, 0, L"{MySort,,,Sort a vector of numeric values,14,1,0,U,{{0,{Inp"
    L"ut,Double,10,,Numeric vector,,{{{,},{,}}},,}}},{},3,,0,0}", 1)
CXlOper* MySort_Impl(CXlOper&, const CXlOper*);

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

CXlOper* MySort_Impl(CXlOper& xloResult, const CXlOper* Input_op)
{
    // Input buffers 
    std::vector<double> Input;
    // Validate and translate inputs
    XlReadVector(*Input_op, Input, L"Input", XLA_TRUNC_ONEMPTY|XLA_TRUNC_ONBLANK
        );
    // End of generated code 
//}}XLP_SRC

    sort(Input.begin(), Input.end());
    xloResult = Input;
    return xloResult.Ret();
}

Uses

CXlOper::operator =