Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
此号慢热型
excelize
提交
24a8d64f
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,发现更多精彩内容 >>
提交
24a8d64f
编写于
9月 01, 2018
作者:
Reage--
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add datavalidation test and fixed struct bug issue #240
上级
05488521
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
48 addition
and
20 deletion
+48
-20
datavalidation.go
datavalidation.go
+14
-18
datavalidation_test.go
datavalidation_test.go
+32
-0
xmlWorksheet.go
xmlWorksheet.go
+2
-2
未找到文件。
datavalidation.go
浏览文件 @
24a8d64f
...
...
@@ -33,9 +33,9 @@ type DataValidationErrorStyle int
// Data validation error styles
const
(
_
DataValidationErrorStyle
=
iota
DataValidationStyleStop
DataValidationStyleWarning
DataValidationStyleInformation
DataValidation
Error
StyleStop
DataValidation
Error
StyleWarning
DataValidation
Error
StyleInformation
)
// Data validation error styles
...
...
@@ -71,16 +71,16 @@ func NewDataValidation(allowBlank bool) *DataValidation {
}
// SetError set error notice
func
(
dd
*
DataValidation
)
SetError
(
style
DataValidationErrorStyle
,
title
,
msg
*
string
)
{
dd
.
Error
=
msg
dd
.
ErrorTitle
=
title
func
(
dd
*
DataValidation
)
SetError
(
style
DataValidationErrorStyle
,
title
,
msg
string
)
{
dd
.
Error
=
&
msg
dd
.
ErrorTitle
=
&
title
strStyle
:=
styleStop
switch
style
{
case
DataValidationStyleStop
:
case
DataValidation
Error
StyleStop
:
strStyle
=
styleStop
case
DataValidationStyleWarning
:
case
DataValidation
Error
StyleWarning
:
strStyle
=
styleWarning
case
DataValidationStyleInformation
:
case
DataValidation
Error
StyleInformation
:
strStyle
=
styleInformation
}
...
...
@@ -89,10 +89,10 @@ func (dd *DataValidation) SetError(style DataValidationErrorStyle, title, msg *s
}
// SetInput set prompt notice
func
(
dd
*
DataValidation
)
SetInput
(
title
,
msg
*
string
)
{
func
(
dd
*
DataValidation
)
SetInput
(
title
,
msg
string
)
{
dd
.
ShowInputMessage
=
convBoolToStr
(
true
)
dd
.
PromptTitle
=
title
dd
.
Prompt
=
msg
dd
.
PromptTitle
=
&
title
dd
.
Prompt
=
&
msg
}
// SetDropList data validation list
...
...
@@ -109,7 +109,7 @@ func (dd *DataValidation) SetRange(f1, f2 int, t DataValidationType, o DataValid
if
dataValidationFormulaStrLen
<
len
(
dd
.
Formula1
)
||
dataValidationFormulaStrLen
<
len
(
dd
.
Formula2
)
{
return
fmt
.
Errorf
(
dataValidationFormulaStrLenErr
)
}
switch
o
{
/*
switch o {
case DataValidationOperatorBetween:
if f1 > f2 {
tmp := formula1
...
...
@@ -122,7 +122,7 @@ func (dd *DataValidation) SetRange(f1, f2 int, t DataValidationType, o DataValid
formula1 = formula2
formula2 = tmp
}
}
}
*/
dd
.
Formula1
=
formula1
dd
.
Formula2
=
formula2
...
...
@@ -190,7 +190,3 @@ func (f *File) AddDataValidation(sheet string, dv *DataValidation) {
xlsx
.
DataValidations
.
DataValidation
=
append
(
xlsx
.
DataValidations
.
DataValidation
,
dv
)
xlsx
.
DataValidations
.
Count
=
len
(
xlsx
.
DataValidations
.
DataValidation
)
}
func
(
f
*
File
)
GetDataValidation
(
sheet
,
sqref
string
)
{
}
datavalidation_test.go
0 → 100644
浏览文件 @
24a8d64f
package
excelize
import
(
"testing"
)
func
TestDataValidation
(
t
*
testing
.
T
)
{
xlsx
:=
NewFile
()
dvRange
:=
NewDataValidation
(
true
)
dvRange
.
Sqref
=
"A1:B2"
dvRange
.
SetRange
(
10
,
20
,
DataValidationTypeWhole
,
DataValidationOperatorBetween
)
dvRange
.
SetError
(
DataValidationErrorStyleStop
,
"error title"
,
"error body"
)
xlsx
.
AddDataValidation
(
"Sheet1"
,
dvRange
)
dvRange
=
NewDataValidation
(
true
)
dvRange
.
Sqref
=
"A3:B4"
dvRange
.
SetRange
(
10
,
20
,
DataValidationTypeWhole
,
DataValidationOperatorGreaterThan
)
dvRange
.
SetInput
(
"input title"
,
"input body"
)
xlsx
.
AddDataValidation
(
"Sheet1"
,
dvRange
)
dvRange
=
NewDataValidation
(
true
)
dvRange
.
Sqref
=
"A5:B6"
dvRange
.
SetDropList
([]
string
{
"1"
,
"2"
,
"3"
})
xlsx
.
AddDataValidation
(
"Sheet1"
,
dvRange
)
// Test write file to given path.
err
:=
xlsx
.
SaveAs
(
"./test/Bookdatavalition.xlsx"
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
}
xmlWorksheet.go
浏览文件 @
24a8d64f
...
...
@@ -18,7 +18,7 @@ type xlsxWorksheet struct {
MergeCells
*
xlsxMergeCells
`xml:"mergeCells"`
PhoneticPr
*
xlsxPhoneticPr
`xml:"phoneticPr"`
ConditionalFormatting
[]
*
xlsxConditionalFormatting
`xml:"conditionalFormatting"`
DataValidations
*
xlsxDataValidations
`xml:"dataValidations"`
DataValidations
*
xlsxDataValidations
`xml:"dataValidations
,omitempty
"`
Hyperlinks
*
xlsxHyperlinks
`xml:"hyperlinks"`
PrintOptions
*
xlsxPrintOptions
`xml:"printOptions"`
PageMargins
*
xlsxPageMargins
`xml:"pageMargins"`
...
...
@@ -298,7 +298,7 @@ type xlsxDataValidations struct {
DisablePrompts
bool
`xml:"disablePrompts,attr,omitempty"`
XWindow
int
`xml:"xWindow,attr,omitempty"`
YWindow
int
`xml:"yWindow,attr,omitempty"`
DataValidation
[]
*
DataValidation
`xml:"dataValidation
,innerxml
"`
DataValidation
[]
*
DataValidation
`xml:"dataValidation"`
}
type
DataValidation
struct
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录