Merge pull request #270 from rentiansheng/valiationdata

data validation drop-down list use sqref cell  issue #268
formula
xuri 6 years ago committed by GitHub
commit 99c9d04f67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -119,6 +119,18 @@ func (dd *DataValidation) SetRange(f1, f2 int, t DataValidationType, o DataValid
return nil
}
// SetSqrefDropList data validation list with current sheet cell rang
func (dd *DataValidation) SetSqrefDropList(sqref string, isCurrentSheet bool) error {
if isCurrentSheet {
dd.Formula1 = sqref
dd.Type = convDataValidationType(typeList)
return nil
}
//isCurrentSheet = false Cross-sheet sqref cell use extLst xml node unrealized
return fmt.Errorf("Cross-sheet sqref cell are not supported")
}
// SetSqref provides function to set data validation range in drop list.
func (dd *DataValidation) SetSqref(sqref string) {
if dd.Sqref == "" {

@ -24,6 +24,14 @@ func TestDataValidation(t *testing.T) {
dvRange.SetDropList([]string{"1", "2", "3"})
xlsx.AddDataValidation("Sheet1", dvRange)
xlsx.SetCellStr("Sheet1", "E1", "E1")
xlsx.SetCellStr("Sheet1", "E2", "E2")
xlsx.SetCellStr("Sheet1", "E3", "E3")
dvRange = NewDataValidation(true)
dvRange.Sqref = "A7:B8"
dvRange.SetSqrefDropList("$E$1:$E$3", true)
xlsx.AddDataValidation("Sheet1", dvRange)
// Test write file to given path.
err := xlsx.SaveAs("./test/Book_data_validation.xlsx")
if err != nil {

Loading…
Cancel
Save