datavalidation_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package xlsx
  2. import (
  3. "fmt"
  4. "testing"
  5. )
  6. func TestDataValidation(t *testing.T) {
  7. var file *File
  8. var sheet *Sheet
  9. var row *Row
  10. var cell *Cell
  11. var err error
  12. var title string = "cell"
  13. var msg string = "cell msg"
  14. file = NewFile()
  15. sheet, err = file.AddSheet("Sheet1")
  16. if err != nil {
  17. fmt.Printf(err.Error())
  18. }
  19. row = sheet.AddRow()
  20. cell = row.AddCell()
  21. cell.Value = "b"
  22. dd := NewXlsxCellDataValidation(true, true, true)
  23. dd.SetDropList([]string{"a", "b", "b"})
  24. dd.SetInput(&title, &msg)
  25. cell.SetDataValidation(dd)
  26. dd = NewXlsxCellDataValidation(true, true, true)
  27. dd.SetDropList([]string{"a", "b", "b"})
  28. title = "col b"
  29. dd.SetInput(&title, &msg)
  30. sheet.Col(2).SetDataValidation(dd, 0, 0)
  31. dd = NewXlsxCellDataValidation(true, true, true)
  32. dd.SetDropList([]string{"a", "b", "b"})
  33. title = "col c range"
  34. dd.SetInput(&title, &msg)
  35. sheet.Col(3).SetDataValidation(dd, 3, 7)
  36. dd = NewXlsxCellDataValidation(true, true, true)
  37. dd.SetDropList([]string{"a", "b", "b"})
  38. title = "col d start 3"
  39. dd.SetInput(&title, &msg)
  40. sheet.Col(4).SetDataValidationWithStart(dd, 1)
  41. if err != nil {
  42. fmt.Printf(err.Error())
  43. }
  44. file.Save("datavalidation.xlsx")
  45. }