forked from p30928647/excelize
fix: datavalidation list error, formula > 255 issue #339
This commit is contained in:
parent
0c5c99e2ad
commit
daf32a37f9
|
@ -108,7 +108,11 @@ func (dd *DataValidation) SetInput(title, msg string) {
|
||||||
|
|
||||||
// SetDropList data validation list.
|
// SetDropList data validation list.
|
||||||
func (dd *DataValidation) SetDropList(keys []string) error {
|
func (dd *DataValidation) SetDropList(keys []string) error {
|
||||||
dd.Formula1 = "\"" + strings.Join(keys, ",") + "\""
|
formula := "\"" + strings.Join(keys, ",") + "\""
|
||||||
|
if dataValidationFormulaStrLen < len(formula) {
|
||||||
|
return fmt.Errorf(dataValidationFormulaStrLenErr)
|
||||||
|
}
|
||||||
|
dd.Formula1 = formula
|
||||||
dd.Type = convDataValidationType(typeList)
|
dd.Type = convDataValidationType(typeList)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,10 +72,14 @@ func TestDataValidationError(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
dvRange = NewDataValidation(true)
|
dvRange = NewDataValidation(true)
|
||||||
dvRange.SetDropList(make([]string, 258))
|
err = dvRange.SetDropList(make([]string, 258))
|
||||||
|
if dvRange.Formula1 != "" {
|
||||||
err = dvRange.SetRange(10, 20, DataValidationTypeWhole, DataValidationOperatorGreaterThan)
|
t.Errorf("data validation error. Formula1 must be empty!")
|
||||||
|
return
|
||||||
|
}
|
||||||
assert.EqualError(t, err, "data validation must be 0-255 characters")
|
assert.EqualError(t, err, "data validation must be 0-255 characters")
|
||||||
|
dvRange.SetRange(10, 20, DataValidationTypeWhole, DataValidationOperatorGreaterThan)
|
||||||
|
dvRange.SetSqref("A9:B10")
|
||||||
|
|
||||||
xlsx.AddDataValidation("Sheet1", dvRange)
|
xlsx.AddDataValidation("Sheet1", dvRange)
|
||||||
if !assert.NoError(t, xlsx.SaveAs(resultFile)) {
|
if !assert.NoError(t, xlsx.SaveAs(resultFile)) {
|
||||||
|
|
Loading…
Reference in New Issue