Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
此号慢热型
excelize
提交
23c73ab5
excelize
项目概览
此号慢热型
/
excelize
与 Fork 源项目一致
Fork自
xuri / excelize
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
excelize
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
已验证
提交
23c73ab5
编写于
2月 09, 2021
作者:
xurime
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
init new formula function: HLOOKUP
上级
30549c5e
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
83 addition
and
4 deletion
+83
-4
calc.go
calc.go
+60
-2
calc_test.go
calc_test.go
+23
-2
未找到文件。
calc.go
浏览文件 @
23c73ab5
...
...
@@ -2214,11 +2214,12 @@ func (fn *formulaFuncs) MDETERM(argsList *list.List) (result formulaArg) {
num
float64
numMtx
=
[][]
float64
{}
err
error
strMtx
=
argsList
.
Front
()
.
Value
.
(
formulaArg
)
.
Matrix
strMtx
[][]
formulaArg
)
if
argsList
.
Len
()
<
1
{
return
return
newErrorFormulaArg
(
formulaErrorVALUE
,
"MDETERM requires at least 1 argument"
)
}
strMtx
=
argsList
.
Front
()
.
Value
.
(
formulaArg
)
.
Matrix
var
rows
=
len
(
strMtx
)
for
_
,
row
:=
range
argsList
.
Front
()
.
Value
.
(
formulaArg
)
.
Matrix
{
if
len
(
row
)
!=
rows
{
...
...
@@ -3705,6 +3706,63 @@ func compareFormulaArgMatrix(lhs, rhs formulaArg, caseSensitive, exactMatch bool
return
criteriaEq
}
// HLOOKUP function 'looks up' a given value in the top row of a data array
// (or table), and returns the corresponding value from another row of the
// array. The syntax of the function is:
//
// HLOOKUP(lookup_value,table_array,row_index_num,[range_lookup])
//
func
(
fn
*
formulaFuncs
)
HLOOKUP
(
argsList
*
list
.
List
)
formulaArg
{
if
argsList
.
Len
()
<
3
{
return
newErrorFormulaArg
(
formulaErrorVALUE
,
"HLOOKUP requires at least 3 arguments"
)
}
if
argsList
.
Len
()
>
4
{
return
newErrorFormulaArg
(
formulaErrorVALUE
,
"HLOOKUP requires at most 4 arguments"
)
}
lookupValue
:=
argsList
.
Front
()
.
Value
.
(
formulaArg
)
tableArray
:=
argsList
.
Front
()
.
Next
()
.
Value
.
(
formulaArg
)
if
tableArray
.
Type
!=
ArgMatrix
{
return
newErrorFormulaArg
(
formulaErrorVALUE
,
"HLOOKUP requires second argument of table array"
)
}
rowArg
:=
argsList
.
Front
()
.
Next
()
.
Next
()
.
Value
.
(
formulaArg
)
.
ToNumber
()
if
rowArg
.
Type
!=
ArgNumber
{
return
newErrorFormulaArg
(
formulaErrorVALUE
,
"HLOOKUP requires numeric row argument"
)
}
rowIdx
,
matchIdx
,
wasExact
,
exactMatch
:=
int
(
rowArg
.
Number
)
-
1
,
-
1
,
false
,
false
if
argsList
.
Len
()
==
4
{
rangeLookup
:=
argsList
.
Back
()
.
Value
.
(
formulaArg
)
.
ToBool
()
if
rangeLookup
.
Type
==
ArgError
{
return
newErrorFormulaArg
(
formulaErrorVALUE
,
rangeLookup
.
Error
)
}
if
rangeLookup
.
Number
==
0
{
exactMatch
=
true
}
}
row
:=
tableArray
.
Matrix
[
0
]
start
:
for
idx
,
mtx
:=
range
row
{
switch
compareFormulaArg
(
mtx
,
lookupValue
,
false
,
exactMatch
)
{
case
criteriaL
:
matchIdx
=
idx
case
criteriaEq
:
matchIdx
=
idx
wasExact
=
true
break
start
}
}
if
matchIdx
==
-
1
{
return
newErrorFormulaArg
(
formulaErrorNA
,
"HLOOKUP no result found"
)
}
if
rowIdx
<
0
||
rowIdx
>=
len
(
tableArray
.
Matrix
)
{
return
newErrorFormulaArg
(
formulaErrorNA
,
"HLOOKUP has invalid row index"
)
}
row
=
tableArray
.
Matrix
[
rowIdx
]
if
wasExact
||
!
exactMatch
{
return
row
[
matchIdx
]
}
return
newErrorFormulaArg
(
formulaErrorNA
,
"HLOOKUP no result found"
)
}
// VLOOKUP function 'looks up' a given value in the left-hand column of a
// data array (or table), and returns the corresponding value from another
// column of the array. The syntax of the function is:
...
...
calc_test.go
浏览文件 @
23c73ab5
...
...
@@ -450,6 +450,7 @@ func TestCalcCellValue(t *testing.T) {
"=SUMSQ(A1,B1,A2,B2,6)"
:
"82"
,
`=SUMSQ("",A1,B1,A2,B2,6)`
:
"82"
,
`=SUMSQ(1,SUMSQ(1))`
:
"2"
,
"=SUMSQ(MUNIT(3))"
:
"0"
,
// TAN
"=TAN(1.047197551)"
:
"1.732050806782486"
,
"=TAN(0)"
:
"0"
,
...
...
@@ -560,6 +561,9 @@ func TestCalcCellValue(t *testing.T) {
"=CHOOSE(4,
\"
red
\"
,
\"
blue
\"
,
\"
green
\"
,
\"
brown
\"
)"
:
"brown"
,
"=CHOOSE(1,
\"
red
\"
,
\"
blue
\"
,
\"
green
\"
,
\"
brown
\"
)"
:
"red"
,
"=SUM(CHOOSE(A2,A1,B1:B2,A1:A3,A1:A4))"
:
"9"
,
// HLOOKUP
"=HLOOKUP(D2,D2:D8,1,FALSE)"
:
"Jan"
,
"=HLOOKUP(F3,F3:F8,3,FALSE)"
:
"34440"
,
// should be Feb
// VLOOKUP
"=VLOOKUP(D2,D:D,1,FALSE)"
:
"Jan"
,
"=VLOOKUP(D2,D:D,1,TRUE)"
:
"Month"
,
// should be Feb
...
...
@@ -739,6 +743,8 @@ func TestCalcCellValue(t *testing.T) {
// LOG10
"=LOG10()"
:
"LOG10 requires 1 numeric argument"
,
`=LOG10("X")`
:
"strconv.ParseFloat: parsing
\"
X
\"
: invalid syntax"
,
// MDETERM
"MDETERM()"
:
"MDETERM requires at least 1 argument"
,
// MOD
"=MOD()"
:
"MOD requires 2 numeric arguments"
,
"=MOD(6,0)"
:
"MOD divide by zero"
,
...
...
@@ -835,6 +841,7 @@ func TestCalcCellValue(t *testing.T) {
"=SUMIF()"
:
"SUMIF requires at least 2 argument"
,
// SUMSQ
`=SUMSQ("X")`
:
"strconv.ParseFloat: parsing
\"
X
\"
: invalid syntax"
,
"=SUMSQ(C1:D2)"
:
"strconv.ParseFloat: parsing
\"
Month
\"
: invalid syntax"
,
// TAN
"=TAN()"
:
"TAN requires 1 numeric argument"
,
`=TAN("X")`
:
"strconv.ParseFloat: parsing
\"
X
\"
: invalid syntax"
,
...
...
@@ -848,6 +855,7 @@ func TestCalcCellValue(t *testing.T) {
// Statistical Functions
// MEDIAN
"=MEDIAN()"
:
"MEDIAN requires at least 1 argument"
,
"=MEDIAN(D1:D2)"
:
"strconv.ParseFloat: parsing
\"
Month
\"
: invalid syntax"
,
// Information Functions
// ISBLANK
"=ISBLANK(A1,A2)"
:
"ISBLANK requires 1 argument"
,
...
...
@@ -914,6 +922,19 @@ func TestCalcCellValue(t *testing.T) {
"=CHOOSE()"
:
"CHOOSE requires 2 arguments"
,
"=CHOOSE(
\"
index_num
\"
,0)"
:
"CHOOSE requires first argument of type number"
,
"=CHOOSE(2,0)"
:
"index_num should be <= to the number of values"
,
// HLOOKUP
"=HLOOKUP()"
:
"HLOOKUP requires at least 3 arguments"
,
"=HLOOKUP(D2,D1,1,FALSE)"
:
"HLOOKUP requires second argument of table array"
,
"=HLOOKUP(D2,D:D,FALSE,FALSE)"
:
"HLOOKUP requires numeric row argument"
,
"=HLOOKUP(D2,D:D,1,FALSE,FALSE)"
:
"HLOOKUP requires at most 4 arguments"
,
"=HLOOKUP(D2,D:D,1,2)"
:
"strconv.ParseBool: parsing
\"
2
\"
: invalid syntax"
,
"=HLOOKUP(D2,D10:D10,1,FALSE)"
:
"HLOOKUP no result found"
,
"=HLOOKUP(D2,D2:D3,4,FALSE)"
:
"HLOOKUP has invalid row index"
,
"=HLOOKUP(D2,C:C,1,FALSE)"
:
"HLOOKUP no result found"
,
"=HLOOKUP(ISNUMBER(1),F3:F9,1)"
:
"HLOOKUP no result found"
,
"=HLOOKUP(INT(1),E2:E9,1)"
:
"HLOOKUP no result found"
,
"=HLOOKUP(MUNIT(2),MUNIT(3),1)"
:
"HLOOKUP no result found"
,
"=HLOOKUP(A1:B2,B2:B3,1)"
:
"HLOOKUP no result found"
,
// VLOOKUP
"=VLOOKUP()"
:
"VLOOKUP requires at least 3 arguments"
,
"=VLOOKUP(D2,D1,1,FALSE)"
:
"VLOOKUP requires second argument of table array"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录