Skip to content

Commit

Permalink
fix: datavalidation list error, formula > 255 issue qax-os#339
Browse files Browse the repository at this point in the history
  • Loading branch information
rentiansheng committed Jan 23, 2019
1 parent 0c5c99e commit daf32a3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 5 additions & 1 deletion datavalidation.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ func (dd *DataValidation) SetInput(title, msg string) {

// SetDropList data validation list.
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)
return nil
}
Expand Down
10 changes: 7 additions & 3 deletions datavalidation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,14 @@ func TestDataValidationError(t *testing.T) {
}

dvRange = NewDataValidation(true)
dvRange.SetDropList(make([]string, 258))

err = dvRange.SetRange(10, 20, DataValidationTypeWhole, DataValidationOperatorGreaterThan)
err = dvRange.SetDropList(make([]string, 258))
if dvRange.Formula1 != "" {
t.Errorf("data validation error. Formula1 must be empty!")
return
}
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)
if !assert.NoError(t, xlsx.SaveAs(resultFile)) {
Expand Down

0 comments on commit daf32a3

Please sign in to comment.