Only strip the leading '=' when escaping XLSX formulae - #658
Merged
Conversation
When escape=True, formula cells had every '=' removed via
cell.value.replace('=', ''), but the option is documented to strip only
the leading '='. A comparison formula like =A1=B1 was corrupted to A1B1
instead of A1=B1. Removing just the leading '=' already disables the
formula, so stripping inner '=' is unnecessary data loss.
Replace the replace('=', '') with cell.value[1:] (the leading '=' is
guaranteed by the startswith('=') guard) and add a regression test.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #658 +/- ##
==========================================
+ Coverage 93.29% 93.30% +0.01%
==========================================
Files 29 29
Lines 3266 3271 +5
==========================================
+ Hits 3047 3052 +5
Misses 219 219 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Summary
When exporting XLSX with
escape=True, formula cells have every=removed:but the option is documented to remove only the leading
=(_xlsx.pydocstring: "formulae will have the leading '=' character removed", and the original feature in #540). A legitimate comparison formula like=A1=B1is therefore corrupted toA1B1instead ofA1=B1.Removing just the leading
=already neutralises the formula (the cell is no longer treated as a formula by Excel), so stripping the inner=is unnecessary data loss.Fix
Replace
cell.value.replace("=", "")withcell.value[1:]. The leading=is guaranteed present by the existingstartswith('=')guard, so this only drops the leading character. The existing=SUM(1+1)→SUM(1+1)behaviour is unchanged.Test
Added
test_xlsx_export_set_escape_formulae_keeps_inner_equals:=A1=B1withescape=Truenow yieldsA1=B1. It fails before the change ('A1=B1' != 'A1B1') and passes after. All existing escape/XLSX tests still pass. Added myself toAUTHORS.