Skip to content

feat: preserve Excel cell formatting via XlsxConfig (fix #53) - #2347

Open
vanity (Vanity-1) wants to merge 1 commit into
microsoft:mainfrom
Vanity-1:feat/xlsx-formatting
Open

feat: preserve Excel cell formatting via XlsxConfig (fix #53)#2347
vanity (Vanity-1) wants to merge 1 commit into
microsoft:mainfrom
Vanity-1:feat/xlsx-formatting

Conversation

@Vanity-1

Copy link
Copy Markdown

Fixes #53

Summary

Adds an opt-in XlsxConfig object to preserve Excel cell number formatting (currency, percentage, thousands separators, dates) when converting .xlsx files to Markdown.

Motivation

pd.read_excel only reads raw cell values, so formatted values like $1,199.00 are emitted as 1199. This PR makes formatting preservation available without breaking existing consumers that parse numeric values from the output.

Changes

  • Add XlsxConfig dataclass with a preserve_formatting: bool = False flag (default keeps current behavior).
  • XlsxConverter now accepts an optional config argument; when preserve_formatting is enabled it reads cells via openpyxl and renders values according to their number format.
  • Currency symbols are extracted from the format string (e.g. $, €, ¥, []) rather than hardcoded.
  • MarkItDown(xlsx_config=XlsxConfig(preserve_formatting=True)) wires the config through �nable_builtins.
  • XlsxConfig is exported from the markitdown package.
  • Adds ests/test_xlsx_converter.py covering currency, percentage, thousands separators, negative values, other currency symbols, dates, and backward compatibility.

Usage

python
from markitdown import MarkItDown, XlsxConfig

md = MarkItDown(xlsx_config=XlsxConfig(preserve_formatting=True))
result = md.convert("invoice.xlsx")

Backward compatibility

Default behavior is unchanged (raw cell values), so existing code that does loat(cell_value) keeps working.

@Vanity-1

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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.

Unable to extract currency from excel formatted cells

1 participant