qax-os / excelize

Go language library for reading and writing Microsoft Excel™ (XLAM / XLSM / XLSX / XLTM / XLTX) spreadsheets
https://xuri.me/excelize
BSD 3-Clause "New" or "Revised" License
17.64k stars 1.69k forks source link

GetDataValidations in a sheet does not list all the validations #1835

Closed ayushjain1908 closed 4 months ago

ayushjain1908 commented 4 months ago

Description Calling GetDataValidations for a particular sheet does not list those validations(list/dropdown types) which reference another sheet in the same workbook.

Steps to reproduce the issue:

  1. Create a workbook with 2 sheets
  2. In first sheet, create a dropdown validation which references some cells in the second sheet.
  3. Call GetDataValidations on the first sheet

Describe the results you received: Cross sheet referenced validations do not appear in the result. Describe the results you expected: Dropdown validation should appear Output of go version:

go version go1.19.3 darwin/amd64

Excelize version or commit ID:

v2.8.0

Environment details (OS, Microsoft Excel™ version, physical, etc.): macOS Ventura 13.3.1

WellOptimized commented 4 months ago

in v2.8.0 the output seems right.here is my test code:

func TestMyTest3(t *testing.T) {
    f := excelize.NewFile()
    defer f.Close()
    _, err := f.NewSheet("Sheet2")
    if err != nil {
        fmt.Println(err)
    }
    f.SetCellValue("Sheet2", "B1", 1)
    f.SetCellValue("Sheet2", "B5", 5)
    dv := excelize.NewDataValidation(true)
    dv.Sqref = "A7:B8"
    dv.SetSqrefDropList("Sheet2!$B$1:$B$5")
    err = f.AddDataValidation("Sheet1", dv)
    if err != nil {
        fmt.Println(err)
    }
    dvs, err := f.GetDataValidations("Sheet1")
    if err != nil {
        fmt.Println(err)
    }
    for _, v := range dvs {
        fmt.Println(v)
    }
}

Output of code: === RUN TestMyTest3

=== RUN   TestMyTest3
&{true <nil> <nil> <nil>  <nil> <nil> false false false A7:B8 list <formula1>Sheet2!$B$1:$B$5</formula1> }
--- PASS: TestMyTest3 (0.00s)
PASS
ok      p1      0.003s

could you please show your test code

ayushjain1908 commented 4 months ago

it is not working for sheets where data validation is added using Excel and we are just reading all the validations in the program, may be working for validations added using the library in Go program I think this recently created PR https://github.com/qax-os/excelize/pull/1834 addresses this issue

xuri commented 4 months ago

Thanks for your issue. The pull request #1834 has been merged. The GetDataValidations function now support get data validations which storage in the extension lists. Please upgrade to the master branch by go get -u github.com/xuri/excelize/v2@master, and this changes will be released in the next version.