Skip to content

Commit

Permalink
This closes #2072, support adjust data validations cross multiple wor…
Browse files Browse the repository at this point in the history
…ksheets (#2073)
  • Loading branch information
gypsy1234 authored Jan 22, 2025
1 parent a45d47d commit 7e614c5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion adjust.go
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ func (f *File) adjustDataValidations(ws *xlsxWorksheet, sheet string, dir adjust
return err
}
if worksheet.DataValidations == nil {
return nil
continue
}
for i := 0; i < len(worksheet.DataValidations.DataValidation); i++ {
dv := worksheet.DataValidations.DataValidation[i]
Expand Down
19 changes: 19 additions & 0 deletions adjust_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,25 @@ func TestAdjustDataValidations(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, formula, dvs[0].Formula1)
})

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) // Adjusted range
})
}

func TestAdjustDrawings(t *testing.T) {
Expand Down

0 comments on commit 7e614c5

Please sign in to comment.