Skip to content

fix(xlsx): preserve Excel formula error values in markdown output - #2898

Open
Parchuri Poojith Kumar (poojithparchuri-iiitk) wants to merge 1 commit into
microsoft:mainfrom
poojithparchuri-iiitk:fix-xlsx-preserve-formula-errors
Open

Parchuri Poojith Kumar (poojithparchuri-iiitk) wants to merge 1 commit into
microsoft:mainfrom
poojithparchuri-iiitk:fix-xlsx-preserve-formula-errors

Conversation

@poojithparchuri-iiitk

Summary

Fixes #2728

When converting .xlsx spreadsheets that contain formula error cells (such as #DIV/0!, #REF!, #VALUE!, #N/A), openpyxl's OpenpyxlReader._convert_cell converts all error cells (cell.data_type == TYPE_ERROR) to np.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

  • In packages/markitdown/src/markitdown/converters/_xlsx_converter.py:
    • Scoped inside the _read_xlsx_sheets context manager, I customized OpenpyxlReader._convert_cell to preserve cell.value when cell.data_type == 'e'.
    • Added keep_default_na=False to pd.read_excel so string error values like #N/A are not converted to NaN.
    • Ensured ox.OpenpyxlReader._convert_cell is safely restored in the finally block.
  • In packages/markitdown/tests/test_xlsx.py:
    • Added test_xlsx_preserves_formula_error_values regression test verifying that #DIV/0!, #REF!, #VALUE!, and #N/A are correctly preserved in the resulting Markdown table.

How I tested this

I ran and validated the tests on my local machine:

  • Ran pytest packages/markitdown/tests/test_xlsx.py: all 25 XLSX tests passed cleanly, including the new regression test.

AI Disclosure: I used AI (Antigravity/Gemini) to assist with investigation, and I personally reviewed the code, wrote regression tests, and verified all tests pass locally.

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.

XLSX conversion loses Excel error values such as #DIV/0! and #REF!

1 participant