-
Notifications
You must be signed in to change notification settings - Fork 5
fix: Dynamic XML namespace prefixes for consistent Excel files #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…ility Dynamically generated sheetData content was missing namespace prefixes, causing XML inconsistency when worksheet root uses 'x:' prefix. Symptoms: Excel opens the file with correct file size but displays an empty worksheet - data is silently ignored due to malformed XML.
When saving, inconsistent namespace prefixes were used, resulting in invalid XML documents. The prefix is now dynamically determined from the document and used consistently across all elements. - Extract _nsPrefix from WorksheetXml. DocumentElement - Replace all hardcoded "x:" prefixes with _nsPrefix - Add using alias RegexMatch to resolve naming conflict - Fix $"" combined with AppendFormat/string.Format calls
📝 WalkthroughWalkthroughThe change modifies EPPlus/ExcelWorksheet.cs to introduce dynamic XML namespace prefix handling for worksheet serialization. A private field Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
EPPlus/ExcelWorksheet.cs (1)
3440-3449: Translate comment to English for consistency.The comment on line 3440 is in German. For codebase consistency and maintainability, it should be in English.
Suggested fix
- // Ermittle den Namespace-Prefix aus dem Dokument + // Determine the namespace prefix from the document var worksheetNode = _worksheetXml.DocumentElement;
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
EPPlus/ExcelWorksheet.cs(27 hunks)
🔇 Additional comments (6)
EPPlus/ExcelWorksheet.cs (6)
58-58: LGTM!The
RegexMatchalias is a clean approach to avoid naming conflicts while maintaining code clarity.
375-375: LGTM!The field is correctly initialized with an empty string default, ensuring consistent behavior for both prefixed and non-prefixed XML output.
1465-1472: LGTM!The namespace prefix is correctly applied to the merged cells XML elements. The formatting with string interpolation is clean and readable.
3653-3653: LGTM!The namespace prefix is consistently applied to all
sheetDataelements and closing tags. The string interpolation pattern$"<{_nsPrefix}sheetData>"correctly handles both prefixed and non-prefixed XML output.Also applies to: 3784-3785
4064-4064: LGTM!The namespace prefix is correctly integrated into all hyperlink XML elements while preserving the existing logic for handling internal and external hyperlinks.
Also applies to: 4073-4074, 4097-4102, 4110-4110
3873-3873: LGTM!The namespace prefix is correctly applied to value elements while preserving the existing XML escaping logic.
| using OfficeOpenXml.Drawing; | ||
| using OfficeOpenXml.Drawing.Chart; | ||
| using OfficeOpenXml.Drawing.Vml; | ||
| using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Search for "RefAndLookup" references in ExcelWorksheet.cs
rg -n "RefAndLookup" EPPlus/ExcelWorksheet.cs || echo "No RefAndLookup found in ExcelWorksheet.cs"
# Also check what types might be imported from that namespace
rg -n "Index\|VLookup\|Lookup\|Offset" EPPlus/ExcelWorksheet.cs | head -20 || echo "No common RefAndLookup types found"Repository: Shane32/EPPlus
Length of output: 125
Remove unused import at line 39.
The OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup namespace is imported but not referenced anywhere in the file. Remove it to keep imports clean.
🤖 Prompt for AI Agents
In EPPlus/ExcelWorksheet.cs around line 39, the using directive
"OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup" is unused; remove
that import line to clean up unused namespaces and then save the file
(optionally run a build or linter to confirm no other references remain).
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.