Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
此号慢热型
excelize
提交
52b1a8e8
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,发现更多精彩内容 >>
已验证
提交
52b1a8e8
编写于
1月 05, 2018
作者:
xurime
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
- Function `SetCellValue()` time.Duration support added, relate issue #176;
- go test updated
上级
e13ccce8
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
31 addition
and
16 deletion
+31
-16
cell.go
cell.go
+25
-13
excelize.go
excelize.go
+4
-3
excelize_test.go
excelize_test.go
+2
-0
未找到文件。
cell.go
浏览文件 @
52b1a8e8
...
@@ -39,6 +39,7 @@ func (f *File) mergeCellsParser(xlsx *xlsxWorksheet, axis string) string {
...
@@ -39,6 +39,7 @@ func (f *File) mergeCellsParser(xlsx *xlsxWorksheet, axis string) string {
// float64
// float64
// string
// string
// []byte
// []byte
// time.Duration
// time.Time
// time.Time
// nil
// nil
//
//
...
@@ -46,6 +47,30 @@ func (f *File) mergeCellsParser(xlsx *xlsxWorksheet, axis string) string {
...
@@ -46,6 +47,30 @@ func (f *File) mergeCellsParser(xlsx *xlsxWorksheet, axis string) string {
// set numbers format by SetCellStyle() method.
// set numbers format by SetCellStyle() method.
func
(
f
*
File
)
SetCellValue
(
sheet
,
axis
string
,
value
interface
{})
{
func
(
f
*
File
)
SetCellValue
(
sheet
,
axis
string
,
value
interface
{})
{
switch
t
:=
value
.
(
type
)
{
switch
t
:=
value
.
(
type
)
{
case
float32
:
f
.
SetCellDefault
(
sheet
,
axis
,
strconv
.
FormatFloat
(
float64
(
value
.
(
float32
)),
'f'
,
-
1
,
32
))
case
float64
:
f
.
SetCellDefault
(
sheet
,
axis
,
strconv
.
FormatFloat
(
float64
(
value
.
(
float64
)),
'f'
,
-
1
,
64
))
case
string
:
f
.
SetCellStr
(
sheet
,
axis
,
t
)
case
[]
byte
:
f
.
SetCellStr
(
sheet
,
axis
,
string
(
t
))
case
time
.
Duration
:
f
.
SetCellDefault
(
sheet
,
axis
,
strconv
.
FormatFloat
(
float64
(
value
.
(
time
.
Duration
)
.
Seconds
()
/
86400
),
'f'
,
-
1
,
32
))
f
.
setDefaultTimeStyle
(
sheet
,
axis
,
21
)
case
time
.
Time
:
f
.
SetCellDefault
(
sheet
,
axis
,
strconv
.
FormatFloat
(
float64
(
timeToExcelTime
(
timeToUTCTime
(
value
.
(
time
.
Time
)))),
'f'
,
-
1
,
64
))
f
.
setDefaultTimeStyle
(
sheet
,
axis
,
22
)
case
nil
:
f
.
SetCellStr
(
sheet
,
axis
,
""
)
default
:
f
.
setCellIntValue
(
sheet
,
axis
,
value
)
}
}
// setCellIntValue provides function to set int value of a cell.
func
(
f
*
File
)
setCellIntValue
(
sheet
,
axis
string
,
value
interface
{})
{
switch
value
.
(
type
)
{
case
int
:
case
int
:
f
.
SetCellInt
(
sheet
,
axis
,
value
.
(
int
))
f
.
SetCellInt
(
sheet
,
axis
,
value
.
(
int
))
case
int8
:
case
int8
:
...
@@ -66,19 +91,6 @@ func (f *File) SetCellValue(sheet, axis string, value interface{}) {
...
@@ -66,19 +91,6 @@ func (f *File) SetCellValue(sheet, axis string, value interface{}) {
f
.
SetCellInt
(
sheet
,
axis
,
int
(
value
.
(
uint32
)))
f
.
SetCellInt
(
sheet
,
axis
,
int
(
value
.
(
uint32
)))
case
uint64
:
case
uint64
:
f
.
SetCellInt
(
sheet
,
axis
,
int
(
value
.
(
uint64
)))
f
.
SetCellInt
(
sheet
,
axis
,
int
(
value
.
(
uint64
)))
case
float32
:
f
.
SetCellDefault
(
sheet
,
axis
,
strconv
.
FormatFloat
(
float64
(
value
.
(
float32
)),
'f'
,
-
1
,
32
))
case
float64
:
f
.
SetCellDefault
(
sheet
,
axis
,
strconv
.
FormatFloat
(
float64
(
value
.
(
float64
)),
'f'
,
-
1
,
64
))
case
string
:
f
.
SetCellStr
(
sheet
,
axis
,
t
)
case
[]
byte
:
f
.
SetCellStr
(
sheet
,
axis
,
string
(
t
))
case
time
.
Time
:
f
.
SetCellDefault
(
sheet
,
axis
,
strconv
.
FormatFloat
(
float64
(
timeToExcelTime
(
timeToUTCTime
(
value
.
(
time
.
Time
)))),
'f'
,
-
1
,
64
))
f
.
setDefaultTimeStyle
(
sheet
,
axis
)
case
nil
:
f
.
SetCellStr
(
sheet
,
axis
,
""
)
default
:
default
:
f
.
SetCellStr
(
sheet
,
axis
,
fmt
.
Sprintf
(
"%v"
,
value
))
f
.
SetCellStr
(
sheet
,
axis
,
fmt
.
Sprintf
(
"%v"
,
value
))
}
}
...
...
excelize.go
浏览文件 @
52b1a8e8
...
@@ -70,10 +70,11 @@ func OpenReader(r io.Reader) (*File, error) {
...
@@ -70,10 +70,11 @@ func OpenReader(r io.Reader) (*File, error) {
}
}
// setDefaultTimeStyle provides function to set default numbers format for
// setDefaultTimeStyle provides function to set default numbers format for
// time.Time type cell value by given worksheet name and cell coordinates.
// time.Time type cell value by given worksheet name, cell coordinates and
func
(
f
*
File
)
setDefaultTimeStyle
(
sheet
,
axis
string
)
{
// number format code.
func
(
f
*
File
)
setDefaultTimeStyle
(
sheet
,
axis
string
,
format
int
)
{
if
f
.
GetCellStyle
(
sheet
,
axis
)
==
0
{
if
f
.
GetCellStyle
(
sheet
,
axis
)
==
0
{
style
,
_
:=
f
.
NewStyle
(
`{"number_format":
22
}`
)
style
,
_
:=
f
.
NewStyle
(
`{"number_format":
`
+
strconv
.
Itoa
(
format
)
+
`
}`
)
f
.
SetCellStyle
(
sheet
,
axis
,
axis
,
style
)
f
.
SetCellStyle
(
sheet
,
axis
,
axis
,
style
)
}
}
}
}
...
...
excelize_test.go
浏览文件 @
52b1a8e8
...
@@ -83,6 +83,8 @@ func TestOpenFile(t *testing.T) {
...
@@ -83,6 +83,8 @@ func TestOpenFile(t *testing.T) {
xlsx
.
SetCellValue
(
"Sheet2"
,
"F16"
,
true
)
xlsx
.
SetCellValue
(
"Sheet2"
,
"F16"
,
true
)
xlsx
.
SetCellValue
(
"Sheet2"
,
"G2"
,
nil
)
xlsx
.
SetCellValue
(
"Sheet2"
,
"G2"
,
nil
)
xlsx
.
SetCellValue
(
"Sheet2"
,
"G4"
,
time
.
Now
())
xlsx
.
SetCellValue
(
"Sheet2"
,
"G4"
,
time
.
Now
())
// 02:46:40
xlsx
.
SetCellValue
(
"Sheet2"
,
"G5"
,
time
.
Duration
(
1e13
))
// Test completion column.
// Test completion column.
xlsx
.
SetCellValue
(
"Sheet2"
,
"M2"
,
nil
)
xlsx
.
SetCellValue
(
"Sheet2"
,
"M2"
,
nil
)
// Test read cell value with given axis large than exists row.
// Test read cell value with given axis large than exists row.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录