Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xuri
excelize
提交
dad8f490
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 搜索 >>
已验证
提交
dad8f490
编写于
9月 09, 2021
作者:
xurime
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
This closes #417 and closes #520, new API `GetCellType` has been added
上级
72d84c0c
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
64 addition
and
1 deletion
+64
-1
calc.go
calc.go
+1
-1
cell.go
cell.go
+50
-0
cell_test.go
cell_test.go
+13
-0
未找到文件。
calc.go
浏览文件 @
dad8f490
...
...
@@ -158,7 +158,7 @@ type formulaCriteria struct {
Condition
string
}
// ArgType is the type
i
f formula argument type.
// ArgType is the type
o
f formula argument type.
type
ArgType
byte
// Formula argument types enumeration.
...
...
cell.go
浏览文件 @
dad8f490
...
...
@@ -20,6 +20,19 @@ import (
"time"
)
// CellType is the type of cell value type.
type
CellType
byte
// Cell value types enumeration.
const
(
CellTypeUnset
CellType
=
iota
CellTypeBool
CellTypeDate
CellTypeError
CellTypeNumber
CellTypeString
)
const
(
// STCellFormulaTypeArray defined the formula is an array formula.
STCellFormulaTypeArray
=
"array"
...
...
@@ -31,6 +44,17 @@ const (
STCellFormulaTypeShared
=
"shared"
)
// cellTypes mapping the cell's data type and enumeration.
var
cellTypes
=
map
[
string
]
CellType
{
"b"
:
CellTypeBool
,
"d"
:
CellTypeDate
,
"n"
:
CellTypeNumber
,
"e"
:
CellTypeError
,
"s"
:
CellTypeString
,
"str"
:
CellTypeString
,
"inlineStr"
:
CellTypeString
,
}
// GetCellValue provides a function to get formatted value from cell by given
// worksheet name and axis in spreadsheet file. If it is possible to apply a
// format to the cell value, it will do so, if not then an error will be
...
...
@@ -43,6 +67,32 @@ func (f *File) GetCellValue(sheet, axis string, opts ...Options) (string, error)
})
}
// GetCellType provides a function to get the cell's data type by given
// worksheet name and axis in spreadsheet file.
func
(
f
*
File
)
GetCellType
(
sheet
,
axis
string
)
(
CellType
,
error
)
{
cellTypes
:=
map
[
string
]
CellType
{
"b"
:
CellTypeBool
,
"d"
:
CellTypeDate
,
"n"
:
CellTypeNumber
,
"e"
:
CellTypeError
,
"s"
:
CellTypeString
,
"str"
:
CellTypeString
,
"inlineStr"
:
CellTypeString
,
}
var
(
err
error
cellTypeStr
string
cellType
CellType
=
CellTypeUnset
)
if
cellTypeStr
,
err
=
f
.
getCellStringFunc
(
sheet
,
axis
,
func
(
x
*
xlsxWorksheet
,
c
*
xlsxC
)
(
string
,
bool
,
error
)
{
return
c
.
T
,
true
,
nil
});
err
!=
nil
{
return
CellTypeUnset
,
err
}
cellType
=
cellTypes
[
cellTypeStr
]
return
cellType
,
err
}
// SetCellValue provides a function to set the value of a cell. The specified
// coordinates should not be in the first row of the table, a complex number
// can be set with string text. The following shows the supported data
...
...
cell_test.go
浏览文件 @
dad8f490
...
...
@@ -244,6 +244,19 @@ func TestGetCellValue(t *testing.T) {
assert
.
NoError
(
t
,
err
)
}
func
TestGetCellType
(
t
*
testing
.
T
)
{
f
:=
NewFile
()
cellType
,
err
:=
f
.
GetCellType
(
"Sheet1"
,
"A1"
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
CellTypeUnset
,
cellType
)
assert
.
NoError
(
t
,
f
.
SetCellValue
(
"Sheet1"
,
"A1"
,
"A1"
))
cellType
,
err
=
f
.
GetCellType
(
"Sheet1"
,
"A1"
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
CellTypeString
,
cellType
)
_
,
err
=
f
.
GetCellType
(
"Sheet1"
,
"A"
)
assert
.
EqualError
(
t
,
err
,
`cannot convert cell "A" to coordinates: invalid cell name "A"`
)
}
func
TestGetCellFormula
(
t
*
testing
.
T
)
{
// Test get cell formula on not exist worksheet.
f
:=
NewFile
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录