Skip to content

adjustDataValidations skips adjusting data validations on subsequent sheets if the first sheet has no data validations #2072

@gypsy1234

Description

@gypsy1234

Description

The adjustDataValidations function, which is invoked by operations such as RemoveCol, skips properly adjusting data validations on subsequent sheets if the first sheet in a workbook has no data validations.

Steps to reproduce the issue

t.Run("no_data_validations_on_first_sheet", func(t *testing.T) {
	f := NewFile()

	// Add Sheet2 and set a data validation
	_, err = f.NewSheet("Sheet2")
	assert.NoError(t, err)
	dv := NewDataValidation(true)
	dv.Sqref = "C5:D6"
	assert.NoError(t, f.AddDataValidation("Sheet2", dv))

	// Adjust Sheet2 by removing a column
	assert.NoError(t, f.RemoveCol("Sheet2", "A"))

	// Verify that data validations on Sheet2 are adjusted correctly
	dvs, err = f.GetDataValidations("Sheet2")
	assert.NoError(t, err)
	assert.Equal(t, "B5:C6", dvs[0].Sqref) // test failed
})

Describe the results you received

DataValidation not updated

Describe the results you expected

DataValidation adjusted

Go version

go version go1.22.2 darwin/arm64

Excelize version or commit ID

2.9.0

Environment

Mac

Validations

  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • The provided reproduction is a minimal reproducible example of the bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions