Skip to content

Fix #53: Preserve Excel cell formatting (currency, percentage, etc.) … - #1325

Open
Preet Patel (preetpatel26) wants to merge 1 commit into
microsoft:mainfrom
preetpatel26:fix-excel-currency-formatting
Open

Preet Patel (preetpatel26) wants to merge 1 commit into
microsoft:mainfrom
preetpatel26:fix-excel-currency-formatting

Conversation

@preetpatel26

Copy link
Copy Markdown

Fix #53: Preserve Excel cell formatting (currency, percentage, etc.) during conversion

  • Use openpyxl to access cell formatting information
  • Apply number formats (currency, percentage, thousands separator)
  • Maintain visual representation from Excel in Markdown output
  • Add tests for currency formatting preservation

…e, etc.) during conversion

- Use openpyxl to access cell formatting information
- Apply number formats (currency, percentage, thousands separator)
- Maintain visual representation from Excel in Markdown output
- Add tests for currency formatting preservation
@preetpatel26

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

available through pandas.read_excel() alone.
"""

def __init__(self):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tackling this - preserving cell formatting is a useful enhancement and something I was recently looking into myself.

However, this PR's approach is a breaking change for downstream consumers who parse numeric values from the markdown output. Code doing float(cell_value) will break when it encounters $1,234.56 instead of 1234.56.

I'd suggest making this opt-in via a config object pattern rather than a boolean flag. This keeps the API extensible without accumulating kwargs over time:

@dataclass
class XlsxConfig:
    preserve_formatting: bool = False
    # future options can be added without breaking changes

class XlsxConverter(DocumentConverter):
    def __init__(self, config: XlsxConfig | None = None):
        self._html_converter = HtmlConverter()
        self._config = config or XlsxConfig()

Then in _format_cell_value(), check self._config.preserve_formatting before applying formatting.

This pattern:

  • Maintains backward compatibility (default = current behavior)
  • Allows users to opt-in explicitly
  • Scales cleanly as more converter options are added
  • Works well with IDE autocomplete and type hints

The same pattern could be extended to other converters (PdfConfig, DocxConfig, etc.) if MarkItDown wants a consistent configuration approach.

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

2 participants