From 7e614c510433a9b7411fd4a339dc015a4885be2c Mon Sep 17 00:00:00 2001 From: gypsy1234 Date: Wed, 22 Jan 2025 19:54:04 +0900 Subject: [PATCH] This closes #2072, support adjust data validations cross multiple worksheets (#2073) --- adjust.go | 2 +- adjust_test.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/adjust.go b/adjust.go index 6696056919..c0d4cdb9aa 100644 --- a/adjust.go +++ b/adjust.go @@ -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] diff --git a/adjust_test.go b/adjust_test.go index fccfdf22b1..0acc8bf2eb 100644 --- a/adjust_test.go +++ b/adjust_test.go @@ -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) {