Skip to content

Only strip the leading '=' when escaping XLSX formulae - #658

Merged
claudep merged 1 commit into
jazzband:masterfrom
vidigoat:fix/xlsx-escape-leading-equals
Jul 15, 2026
Merged

Only strip the leading '=' when escaping XLSX formulae#658
claudep merged 1 commit into
jazzband:masterfrom
vidigoat:fix/xlsx-escape-leading-equals

Conversation

@vidigoat

Copy link
Copy Markdown
Contributor

Summary

When exporting XLSX with escape=True, formula cells have every = removed:

cell.value = cell.value.replace("=", "")

but the option is documented to remove only the leading = (_xlsx.py docstring: "formulae will have the leading '=' character removed", and the original feature in #540). A legitimate comparison formula like =A1=B1 is therefore corrupted to A1B1 instead of A1=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("=", "") with cell.value[1:]. The leading = is guaranteed present by the existing startswith('=') 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=B1 with escape=True now yields A1=B1. It fails before the change ('A1=B1' != 'A1B1') and passes after. All existing escape/XLSX tests still pass. Added myself to AUTHORS.

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.

@claudep claudep left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@claudep claudep added the changelog: Fixed For any bug fixes label Jul 15, 2026
@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.30%. Comparing base (e7fdb92) to head (d9d3205).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@claudep
claudep merged commit 9f31292 into jazzband:master Jul 15, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog: Fixed For any bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants