Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hw1-ry2330 #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion G5260.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<ProjectGuid>{03095D3C-723C-4BBB-89A0-27B9DC01FB3D}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>G5260</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
Expand Down
46 changes: 22 additions & 24 deletions sort.cpp
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
// sort.cpp - std::sort from the STL
#include <algorithm>
#include <xutility>
//!!! 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;
}