From 7d43cb41b5370895b29f10800cc1858acc99ef4c Mon Sep 17 00:00:00 2001 From: ry2330 Date: Mon, 25 Sep 2017 15:32:05 -0400 Subject: [PATCH] hw1-ry2330 --- G5260.vcxproj | 2 +- sort.cpp | 46 ++++++++++++++++++++++------------------------ 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/G5260.vcxproj b/G5260.vcxproj index a25452c..79cb221 100644 --- a/G5260.vcxproj +++ b/G5260.vcxproj @@ -23,7 +23,7 @@ {03095D3C-723C-4BBB-89A0-27B9DC01FB3D} Win32Proj G5260 - 8.1 + 10.0.15063.0 diff --git a/sort.cpp b/sort.cpp index 3326ee6..65a6ec7 100644 --- a/sort.cpp +++ b/sort.cpp @@ -1,36 +1,34 @@ // sort.cpp - std::sort from the STL -#include -#include +//!!! Write xll_sort that calls std::sort and hook it up to XLL.SORT in Excel. #include "G5260.h" using namespace xll; AddIn xai_sort( - Function(XLL_LPOPER, L"?xll_sort", L"XLL.SORT") - .Arg(XLL_LPOPER, L"range", L"is a range.") - .FunctionHelp(L"Sort entries from range.") - .Category(CATEGORY) + Function(XLL_LPOPER, L"?xll_sort", L"XLL.SORT") + .Arg(XLL_LPOPER, L"range", L"is a range.") + .FunctionHelp(L"Sort adjacent entries from range.") + .Category(CATEGORY) ); LPOPER WINAPI xll_sort(LPOPER po) { #pragma XLLEXPORT - static OPER o; + static OPER o; - try { - std::sort(po->begin(), po->end()); - if (po->rows() == 1) { - o.resize(1, po->columns()); - } - else { - o.resize(po->rows(), po->columns()); - } - std::copy(po->begin(), po->end(), o.begin()); - } - catch (const std::exception& ex) { - XLL_ERROR(ex.what()); - o = OPER(xlerr::NA); - } - - return &o; -} + try { + std::sort(po->begin(), po->end()); + if (po->rows() == 1) { + o.resize(1, std::distance(po->begin(), po->end())); + } + else { + o.resize(std::distance(po->begin(), po->end()), 1); + } + std::copy(po->begin(), po->end(), o.begin()); + } + catch (const std::exception& ex) { + XLL_ERROR(ex.what()); + o = OPER(xlerr::NA); + } + return &o; +} \ No newline at end of file