Skip to content

Conversation

@mrinalcodez
Copy link

This PR fixes Issue #63101, where Styler.to_excel() incorrectly lowercased characters inside Excel number-format literals. Because Excel custom number formats are case-sensitive, this caused formats such as number-format: #,,"M"; to become #,,"m"; when written to the XLSX file. The resulting entry in styles.xml was sometimes valid but semantically wrong, and in some cases (depending on user CSS input) produced malformed XML that triggered Excel’s content-recovery warning.

Fixes implemented:
The CSS parsing logic in pandas/io/formats/css.py lowercased all CSS values unconditionally via .lower(). This behavior is correct for CSS identifiers (e.g., colors, keywords), but incorrect for:

  • quoted strings, which are case-sensitive by definition
  • Excel number formats, which rely on quoted string literals
  • downstream XML generation for Excel styles

@mrinalcodez mrinalcodez changed the title Preserve case inside quoted CSS values to fix Excel number-format literal lowercasing (closes #63101) BUG: Preserve case inside quoted CSS values to fix Excel number-format literal lowercasing (closes #63101) Nov 15, 2025
@mrinalcodez
Copy link
Author

pre-commit.ci autofix

parthkandharkar added a commit to parthkandharkar/pandas that referenced this pull request Nov 15, 2025
@parthkandharkar
Copy link

Sorry for the noise, one of my commits accidentally referenced this PR number, so GitHub auto-linked it here. Please ignore that cross-reference.

@mrinalcodez
Copy link
Author

Hi! I wanted to check on the status of this PR.
I believe it addresses the issue as discussed, but I’m happy to revise anything if needed.
Thanks for your time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Strings in Excel number formats do not preserve case

2 participants