Repository navigation
Fix #53: Preserve Excel cell formatting (currency, percentage, etc.) … - #1325
Preet Patel (preetpatel26) wants to merge 1 commit into
Conversation
…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
|
@microsoft-github-policy-service agree |
| available through pandas.read_excel() alone. | ||
| """ | ||
|
|
||
| def __init__(self): |
There was a problem hiding this comment.
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.
Fix #53: Preserve Excel cell formatting (currency, percentage, etc.) during conversion