forked from p30928647/excelize
Complete unit testing case for data validation
This commit is contained in:
parent
b4a6e61ec3
commit
4f47737d64
|
@ -7,6 +7,7 @@ go:
|
|||
- 1.8.x
|
||||
- 1.9.x
|
||||
- 1.10.x
|
||||
- 1.11.x
|
||||
|
||||
os:
|
||||
- linux
|
||||
|
|
|
@ -127,15 +127,24 @@ func (dd *DataValidation) SetRange(f1, f2 int, t DataValidationType, o DataValid
|
|||
return nil
|
||||
}
|
||||
|
||||
// SetSqrefDropList data validation list with current sheet cell rang
|
||||
// SetSqrefDropList provides set data validation on a range with source
|
||||
// reference range of the worksheet by given data validation object and
|
||||
// worksheet name. The data validation object can be created by
|
||||
// NewDataValidation function. For example, set data validation on
|
||||
// Sheet1!A7:B8 with validation criteria source Sheet1!E1:E3 settings, create
|
||||
// in-cell dropdown by allowing list source:
|
||||
//
|
||||
// dvRange := excelize.NewDataValidation(true)
|
||||
// dvRange.Sqref = "A7:B8"
|
||||
// dvRange.SetSqrefDropList("E1:E3", true)
|
||||
// xlsx.AddDataValidation("Sheet1", dvRange)
|
||||
//
|
||||
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")
|
||||
}
|
||||
|
||||
|
@ -206,7 +215,7 @@ func convDataValidationOperatior(o DataValidationOperator) string {
|
|||
// xlsx.AddDataValidation("Sheet1", dvRange)
|
||||
//
|
||||
// Example 3, set data validation on Sheet1!A5:B6 with validation criteria
|
||||
// settings, create in-cell dropdown by allow list source:
|
||||
// settings, create in-cell dropdown by allowing list source:
|
||||
//
|
||||
// dvRange = excelize.NewDataValidation(true)
|
||||
// dvRange.Sqref = "A5:B6"
|
||||
|
|
|
@ -19,6 +19,8 @@ func TestDataValidation(t *testing.T) {
|
|||
dvRange.Sqref = "A1:B2"
|
||||
dvRange.SetRange(10, 20, DataValidationTypeWhole, DataValidationOperatorBetween)
|
||||
dvRange.SetError(DataValidationErrorStyleStop, "error title", "error body")
|
||||
dvRange.SetError(DataValidationErrorStyleWarning, "error title", "error body")
|
||||
dvRange.SetError(DataValidationErrorStyleInformation, "error title", "error body")
|
||||
xlsx.AddDataValidation("Sheet1", dvRange)
|
||||
|
||||
dvRange = NewDataValidation(true)
|
||||
|
@ -36,12 +38,20 @@ func TestDataValidation(t *testing.T) {
|
|||
xlsx.SetCellStr("Sheet1", "E2", "E2")
|
||||
xlsx.SetCellStr("Sheet1", "E3", "E3")
|
||||
dvRange = NewDataValidation(true)
|
||||
dvRange.Sqref = "A7:B8"
|
||||
dvRange.SetSqref("A7:B8")
|
||||
dvRange.SetSqref("A7:B8")
|
||||
dvRange.SetSqrefDropList("$E$1:$E$3", true)
|
||||
err := dvRange.SetSqrefDropList("$E$1:$E$3", false)
|
||||
t.Log(err)
|
||||
xlsx.AddDataValidation("Sheet1", dvRange)
|
||||
|
||||
dvRange = NewDataValidation(true)
|
||||
dvRange.SetDropList(make([]string, 258))
|
||||
err = dvRange.SetRange(10, 20, DataValidationTypeWhole, DataValidationOperatorGreaterThan)
|
||||
t.Log(err)
|
||||
|
||||
// Test write file to given path.
|
||||
err := xlsx.SaveAs("./test/Book_data_validation.xlsx")
|
||||
err = xlsx.SaveAs("./test/Book_data_validation.xlsx")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue