This closes #2072, support adjust data validations cross multiple worksheets (#2073)

This commit is contained in:
gypsy1234 2025-01-22 19:54:04 +09:00 committed by GitHub
parent a45d47d57c
commit 7e614c5104
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 1 deletions

View File

@ -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]

View File

@ -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) {