Skip to content

Commit

Permalink
Merge pull request #340 from rentiansheng/datavalidation_formula_error
Browse files Browse the repository at this point in the history
fix: datavalidation list error, formula > 255 issue #339
  • Loading branch information
xuri authored Jan 24, 2019
2 parents 0c5c99e + daf32a3 commit 36fc39f
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 36fc39f

Please sign in to comment.