Repository navigation
fix(xlsx): preserve Excel formula error values in markdown output - #2898
Open
Parchuri Poojith Kumar (poojithparchuri-iiitk) wants to merge 1 commit into
Conversation
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
Fixes #2728
When converting
.xlsxspreadsheets that contain formula error cells (such as#DIV/0!,#REF!,#VALUE!,#N/A),openpyxl'sOpenpyxlReader._convert_cellconverts all error cells (cell.data_type == TYPE_ERROR) tonp.nan. As a result, formula errors are dropped and rendered as empty cells in the generated Markdown tables, making calculation errors indistinguishable from empty cells.Changes I made
packages/markitdown/src/markitdown/converters/_xlsx_converter.py:_read_xlsx_sheetscontext manager, I customizedOpenpyxlReader._convert_cellto preservecell.valuewhencell.data_type == 'e'.keep_default_na=Falsetopd.read_excelso string error values like#N/Aare not converted toNaN.ox.OpenpyxlReader._convert_cellis safely restored in thefinallyblock.packages/markitdown/tests/test_xlsx.py:test_xlsx_preserves_formula_error_valuesregression test verifying that#DIV/0!,#REF!,#VALUE!, and#N/Aare correctly preserved in the resulting Markdown table.How I tested this
I ran and validated the tests on my local machine:
pytest packages/markitdown/tests/test_xlsx.py: all 25 XLSX tests passed cleanly, including the new regression test.