Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xuri
excelize
提交
e4497c49
excelize
项目概览
xuri
/
excelize
通知
13
Star
2
Fork
4
代码
文件
提交
分支
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 搜索 >>
未验证
提交
e4497c49
编写于
1月 25, 2024
作者:
J
Jerry
提交者:
GitHub
1月 25, 2024
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ref #65, new formula function: DBCS (#1791)
Co-authored-by:
N
wujierui
<
wujierui@jimabrand.com
>
上级
9b078980
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
48 addition
and
0 deletion
+48
-0
calc.go
calc.go
+33
-0
calc_test.go
calc_test.go
+15
-0
未找到文件。
calc.go
浏览文件 @
e4497c49
...
...
@@ -455,6 +455,7 @@ type formulaFuncs struct {
// DAYS
// DAYS360
// DB
// DBCS
// DCOUNT
// DCOUNTA
// DDB
...
...
@@ -13566,6 +13567,38 @@ func (fn *formulaFuncs) concat(name string, argsList *list.List) formulaArg {
return newStringFormulaArg(buf.String())
}
// DBCS converts half-width (single-byte) letters within a character string to
// full-width (double-byte) characters. The syntax of the function is:
//
// DBCS(text)
func (fn *formulaFuncs) DBCS(argsList *list.List) formulaArg {
if argsList.Len() != 1 {
return newErrorFormulaArg(formulaErrorVALUE, "DBCS requires 1 argument")
}
arg := argsList.Front().Value.(formulaArg)
if arg.Type == ArgError {
return arg
}
if fn.f.options.CultureInfo == CultureNameZhCN {
var chars []string
for _, r := range arg.Value() {
code := r
if code == 32 {
code = 12288
} else {
code += 65248
}
if (code < 32 || code > 126) && r != 165 && code < 65381 {
chars = append(chars, string(code))
} else {
chars = append(chars, string(r))
}
}
return newStringFormulaArg(strings.Join(chars, ""))
}
return arg
}
// EXACT function tests if two supplied text strings or values are exactly
// equal and if so, returns TRUE; Otherwise, the function returns FALSE. The
// function is case-sensitive. The syntax of the function is:
...
...
calc_test.go
浏览文件 @
e4497c49
...
...
@@ -1723,6 +1723,10 @@ func TestCalcCellValue(t *testing.T) {
"=CONCATENATE(TRUE(),1,FALSE(),
\"
0
\"
,INT(2))"
:
"TRUE1FALSE02"
,
"=CONCATENATE(MUNIT(2))"
:
"1001"
,
"=CONCATENATE(A1:B2)"
:
"1425"
,
// DBCS
"=DBCS(
\"\"
)"
:
""
,
"=DBCS(123.456)"
:
"123.456"
,
"=DBCS(
\"
123.456
\"
)"
:
"123.456"
,
// EXACT
"=EXACT(1,
\"
1
\"
)"
:
"TRUE"
,
"=EXACT(1,1)"
:
"TRUE"
,
...
...
@@ -3836,6 +3840,9 @@ func TestCalcCellValue(t *testing.T) {
// CONCATENATE
"=CONCATENATE(NA())"
:
{
"#N/A"
,
"#N/A"
},
"=CONCATENATE(1,1/0)"
:
{
"#DIV/0!"
,
"#DIV/0!"
},
// DBCS
"=DBCS(NA())"
:
{
"#N/A"
,
"#N/A"
},
"=DBCS()"
:
{
"#VALUE!"
,
"DBCS requires 1 argument"
},
// EXACT
"=EXACT()"
:
{
"#VALUE!"
,
"EXACT requires 2 arguments"
},
"=EXACT(1,2,3)"
:
{
"#VALUE!"
,
"EXACT requires 2 arguments"
},
...
...
@@ -5194,6 +5201,14 @@ func TestCalcDatabase(t *testing.T) {
}
}
func
TestCalcDBCS
(
t
*
testing
.
T
)
{
f
:=
NewFile
(
Options
{
CultureInfo
:
CultureNameZhCN
})
assert
.
NoError
(
t
,
f
.
SetCellFormula
(
"Sheet1"
,
"A1"
,
"=DBCS(
\"
`~·!@#$¥%…^&*()_-+=[]{}
\\
|;:'
\"\"
<,>.?/01234567890 abc ABC
\uff65\uff9e\uff9f
\uff74\uff78\uff7e\uff99\"
)"
))
result
,
err
:=
f
.
CalcCellValue
(
"Sheet1"
,
"A1"
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
"
\uff40\uff5e\u00b7\uff01\uff20\uff03\uff04\u00a5\uff05\u2026\uff3e\uff06\uff0a\uff08\uff09\uff3f\uff0d\uff0b\uff1d\uff3b\uff3d\uff5b\uff5d\uff3c\uff5c\uff1b\uff1a\uff07\uff02\uff1c\uff0c\uff1e\uff0e\uff1f\uff0f\uff10\uff11\uff12\uff13\uff14\uff15\uff16\uff17\uff18\uff19\uff10\u3000\uff41\uff42\uff43\u3000\uff21\uff22\uff23\u3000\uff65\uff9e\uff9f\u3000\uff74\uff78\uff7e\uff99
"
,
result
)
}
func
TestCalcFORMULATEXT
(
t
*
testing
.
T
)
{
f
,
formulaText
:=
NewFile
(),
"=SUM(B1:C1)"
assert
.
NoError
(
t
,
f
.
SetCellFormula
(
"Sheet1"
,
"A1"
,
formulaText
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录