Skip to content

Fix formula text truncated on XML character references - #348

Merged
MathNya merged 1 commit into
MathNya:masterfrom
sentinelt:fix/data-validation-formula-char-refs
Jul 28, 2026
Merged

Fix formula text truncated on XML character references#348
MathNya merged 1 commit into
MathNya:masterfrom
sentinelt:fix/data-validation-formula-char-refs

Conversation

@sentinelt

@sentinelt sentinelt commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

dataValidation / formula character data that contains XML numeric character references (e.g. – for an en-dash) was truncated when reading .xlsx files.

Root cause

quick-xml emits those references as Event::GeneralRef nodes between successive Event::Text fragments. The parsers for DataValidation (formula1 / formula2) and Formula replaced the accumulator on each Text event and ignored GeneralRef, so only the last text fragment survived.

Example list formula in a real workbook:

<formula1>"0&#8211;3 years ago,4&#8211;5 years ago,6&#8211;7 years ago"</formula1>

was read as:

7 years ago"

instead of the full list string.

Fix

  • Append successive Text events instead of overwriting
  • Resolve and append GeneralRef (numeric char refs + common named entities)
  • Shared helpers: append_xml_text / append_xml_general_ref
  • Unit tests covering en-dash list formulas and plain list formulas
  • Close a missing brace in number_formater tests that broke compilation of the local tree

quick-xml emits numeric character references (e.g. &#8211;) as GeneralRef
events between Text fragments. DataValidation and Formula parsers replaced
the accumulator on each Text event and ignored GeneralRef, so list
formulas were truncated to the last fragment. Append Text and GeneralRef
instead, with unit coverage for en-dash list formulas.

Also close a missing brace in number_formater tests that broke compilation.
@MathNya

MathNya commented Jul 28, 2026

Copy link
Copy Markdown
Owner

@sentinelt
Thank you for the PR.
Since there were no issues with the changes, I’ll go ahead and merge them.
(I’ll make a few minor adjustments after merging.)

There are a few other instances of this, so it looks like we’ll need to review the entire code.

@MathNya
MathNya merged commit 461dc05 into MathNya:master Jul 28, 2026
@c-git

c-git commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

@MathNya after you've done the update in the other places as well, please let me know so I can test if it also fixes my issue in #336

@MathNya

MathNya commented Aug 4, 2026

Copy link
Copy Markdown
Owner

@c-git
We have addressed all the issues.
Please check #336.

@c-git

c-git commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Thank you. I can confirm this fixed my problem. Sorry I never got time to work on it. Been under pressure.

PS. The hash of the output xlsx file has changed but I wasn't able to easily find the difference. It still has the some contents when saved as csv. I recall there was a tool you used to compare the files but I can't recall what it was and can't remember in which pr or issue you'd spoken about it. Would you mind sharing the tool again so I can look into what changed in the file please.

@c-git

c-git commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

FYI I extracted the xml from the zip, pretty printed it, and diffed it in vscode and found the change. It was to a column width. Would still love to know what tool you use cuz I'm sure that would have been faster but just FYI since I mentioned that something changed just reporting back.

image

@MathNya

MathNya commented Aug 5, 2026

Copy link
Copy Markdown
Owner

@c-git
Thank you for your prompt response.

I’m currently using this VSCode extension to check XML.
https://marketplace.visualstudio.com/items?itemName=yuenm18.ooxml-viewer

(There used to be a very user-friendly Google Chrome extension, but it’s now deprecated and can no longer be used.)

@c-git

c-git commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

I’m currently using this VSCode extension to check XML. https://marketplace.visualstudio.com/items?itemName=yuenm18.ooxml-viewer

Thank you very much

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.

3 participants