Fix: Handle extLst in data validation for deletion (#2133)#2137
Merged
Conversation
This commit resolves issue #2133 by ensuring that data validations defined within an <extLst> (Extension List) are correctly parsed and accessible. This prevents DeleteDataValidation from prematurely returning nil when ws.DataValidations was previously unpopulated due to unhandled extLst elements. Key changes: - Modified internal 'xlsxDataValidation' struct to include an 'ExtLst' field, enabling the parsing of <extLst> from worksheet XML. - Added 'ExtLstXML' string field to the public 'DataValidation' struct to expose the raw XML content of the extension list to users. - Updated the 'getDataValidations' helper function to correctly transfer the extLst XML content from the internal structure to the public DataValidation object. These changes ensure that data validations, including those defined via extensions, are fully loaded, allowing DeleteDataValidation to operate correctly on them.
Contributor
Author
|
extLstValidationTest_after_delete_attempt.xlsx The original file and the file deleted extLst validation |
xuri
requested changes
May 17, 2025
Member
xuri
left a comment
There was a problem hiding this comment.
Thanks for your issue. Unit test is required for coverage this changes.
xuri
requested changes
May 17, 2025
- Support delete data validation by given with multiple cell ranges with reference sequence slice or blank separated reference sequence string - Update unit tests
xuri
approved these changes
May 17, 2025
Member
xuri
left a comment
There was a problem hiding this comment.
I've fix code review issues based on your branch. Thanks for your contribution.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2137 +/- ##
=======================================
Coverage 99.23% 99.23%
=======================================
Files 32 32
Lines 30243 30303 +60
=======================================
+ Hits 30012 30072 +60
Misses 153 153
Partials 78 78
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This pull request addresses an issue where data validations defined within an
<extLst>(Extension List) in the worksheet XML were not being fully parsed. This incomplete parsing led tows.DataValidationsbeingnilin certain cases, causing theDeleteDataValidationfunction to return prematurely without attempting to delete the relevant data validation rules.The key changes implemented in this PR are:
xlsxDataValidationstruct by adding anExtLstfield. This allows theexcelizelibrary to correctly parse and capture the content of<extLst>elements from the worksheet XML.ExtLstXMLstring field to the publicDataValidationstruct. This field exposes the raw XML content of the extension list associated with a data validation rule, making this information accessible to users of the library.getDataValidationshelper function to ensure that the raw XML content from the parseddv.ExtLst.Ext(internal struct) is correctly transferred to thedataValidation.ExtLstXMLfield of the publicDataValidationobject.These modifications ensure that all data validation rules, including those defined via XML extensions, are fully loaded and represented. Consequently,
DeleteDataValidationcan now correctly identify and operate on these data validations.Related Issue
Fixes #2133
Motivation and Context
This change is required to fix a bug where
DeleteDataValidationwould not work for Excel files if their data validations were defined using extension list (extLst) elements. The original issue (#2133) describes how the function would return early because theDataValidationsfield on the worksheet object wasnil, due toextLstnot being parsed. This PR ensures that such data validations are properly read, allowing them to be managed (specifically, deleted) correctly by the library, thus improving compatibility and correctness when handling modern Excel files.How Has This Been Tested
The changes have been tested as follows:
excelizeproject were run usinggo test -v ./...after applying the changes, and all tests passed successfully. This ensures no existing functionality was broken.extLstDebugFile.xlsx) was manually created, containing a data validation rule on sheetSheetWithExtLstDVcellB1that was intentionally defined using an<extLst>element (specifically,<ext uri="{CCE6A557-97BC-4b89-ADB6-D9C93CAAB3DF}...">and<ext uri="{FAC63952-8661-4B54-9155-E8378167997E}...">).main.goin a separate tester project موادreplacedirective) was used to:excelizelibrary.GetDataValidations("SheetWithExtLstDV")and verify (via logging) that theExtLstXMLfield of the returnedDataValidationobject was correctly populated with the XML content from theextLst.DeleteDataValidation("SheetWithExtLstDV", "B1").GetDataValidations("SheetWithExtLstDV")again and verify that no data validations were returned, confirming successful deletion in memory.f.SaveAs().excelizelibrary.Testing Environment:
Types of changes
Checklist