-
Notifications
You must be signed in to change notification settings - Fork 58
/
xll_range.cpp
133 lines (113 loc) · 3.27 KB
/
xll_range.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// xll_range.cpp - Range operations
#include "G5260.h"
using namespace xll;
static AddIn xai_range_set(
Function(XLL_HANDLE, L"?xll_range_set", L"RANGE.SET")
.Arg(XLL_LPOPER, L"range", L"is a range of cells.")
.Uncalced()
.Category(CATEGORY)
.FunctionHelp(L"Return a handle to a range of cells.")
);
HANDLEX WINAPI xll_range_set(LPOPER po)
{
#pragma XLLEXPORT
xll::handle<OPER> ho(new OPER(*po));
return ho.get();
}
static AddIn xai_range_get(
Function(XLL_LPOPER, L"?xll_range_get", L"RANGE.GET")
.Arg(XLL_HANDLE, L"handle", L"is a handle to a range of cells returned.")
.Category(CATEGORY)
.FunctionHelp(L"Return a range of cells given a handle.")
);
LPOPER WINAPI xll_range_get(HANDLEX ho)
{
#pragma XLLEXPORT
xll::handle<OPER> h(ho);
return h.ptr();
}
static AddIn xai_range_mask(
Function(XLL_LPOPER, L"?xll_range_mask", L"RANGE.MASK")
.Arg(XLL_LPOPER, L"range", L"is a range of cells returned.")
.Arg(XLL_LPOPER, L"mask", L"is a range of the same shape to be used as a mask.")
.Category(CATEGORY)
.FunctionHelp(L"Return a range of cells not in the mask.")
);
LPOPER WINAPI xll_range_mask(LPXLOPER12 pr, LPXLOPER12 pm)
{
#pragma XLLEXPORT
static OPER o;
try {
ensure (pr->val.array.rows == pm->val.array.rows);
ensure (pr->val.array.columns == pm->val.array.columns);
o.resize(pr->val.array.rows, pr->val.array.columns);
int j = 0;
for (int i = 0; i < o.size(); ++i) {
if (!OPER(pm->val.array.lparray[i])) {
o[j++] = pr->val.array.lparray[i];
}
}
if (pr->val.array.columns == 1)
o.resize(j, 1);
else
o.resize(1, j);
}
catch (const std::exception& ex) {
XLL_ERROR(ex.what());
o = OPER(xlerr::NA);
}
return &o;
}
static AddIn xai_range_push_back(
Function(XLL_LPOPER, L"?xll_range_push_back", L"RANGE.STACK")
.Arg(XLL_LPOPER, L"range", L"is a range of cells.")
.Arg(XLL_LPOPER, L"range", L"is a range of cells.")
.Arg(XLL_LPOPER, L"range", L"is a range of cells.")
.Category(CATEGORY)
.FunctionHelp(L"Return ranges joined together.")
);
LPOPER WINAPI xll_range_push_back(const LPOPER po0, const LPOPER po1, const LPOPER po2)
{
#pragma XLLEXPORT
static OPER o;
try {
o = *po0;
if (*po1) {
o.push_back(*po1);
if (*po2) {
o.push_back(*po2);
}
}
}
catch (const std::exception& ex) {
XLL_ERROR(ex.what());
o = OPER(xlerr::NA);
}
return &o;
}
static AddIn xai_range_make(
Function(XLL_LPOPER, L"?xll_range_make", L"RANGE.MAKE")
.Arg(XLL_WORD, L"rows", L"is the number of rows in the returned range.")
.Arg(XLL_WORD, L"columns", L"is a numberg of columns in the returned range.")
.Category(CATEGORY)
.FunctionHelp(L"Return ranges with given rows and columns.")
);
LPOPER WINAPI xll_range_make(WORD rows, WORD columns)
{
#pragma XLLEXPORT
static OPER o;
try {
o.resize(rows, columns);
}
catch (const std::exception& ex) {
XLL_ERROR(ex.what());
o = OPER(xlerr::NA);
}
return &o;
}
/*
static Auto<Close> xac_handle_oper([]() {
xll::handle<OPER>::gc();
return TRUE;
});
*/