forked from p30928647/excelize
data validation drop-down list use sqref cell issue #268
This commit is contained in:
parent
2da107d3b2
commit
93cbafb0e2
|
@ -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…
Reference in New Issue