From 93cbafb0e2ff5df0236d543650712cd175cd789d Mon Sep 17 00:00:00 2001 From: rentiansheng Date: Tue, 4 Sep 2018 13:40:53 +0800 Subject: [PATCH] data validation drop-down list use sqref cell issue #268 --- datavalidation.go | 12 ++++++++++++ datavalidation_test.go | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/datavalidation.go b/datavalidation.go index 914e877..010615c 100644 --- a/datavalidation.go +++ b/datavalidation.go @@ -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 == "" { diff --git a/datavalidation_test.go b/datavalidation_test.go index 32f9059..f3db81c 100644 --- a/datavalidation_test.go +++ b/datavalidation_test.go @@ -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 {