Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ayushjain1908 opened this issue Mar 1, 2024 · 3 comments · Fixed by #1834
Closed

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

ayushjain1908 opened this issue Mar 1, 2024 · 3 comments · Fixed by #1834
Labels
enhancement New feature or request

Comments

@ayushjain1908
Copy link

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
Copy link

WellOptimized commented Mar 2, 2024

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
Copy link
Author

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 #1834 addresses this issue

@xuri xuri added the enhancement New feature or request label Mar 5, 2024
xuri added a commit to iEvan-lhr/excelize that referenced this issue Mar 5, 2024
@xuri xuri closed this as completed in #1834 Mar 6, 2024
xuri pushed a commit that referenced this issue Mar 6, 2024
@xuri
Copy link
Member

xuri commented Mar 6, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
No open projects
Status: Improve the Compatibility
3 participants