feat: add sub-sheet selection for Excel files - #2298
feat: add sub-sheet selection for Excel files#2298Utkarsh Verma (heyutkarshverma) wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request adds Excel sub-sheet selection capabilities to markitdown, wiring new CLI options through to the Excel converters so users can list available sheets, select specific sheets, or choose sheets interactively.
Changes:
- Added CLI flags
--list-sheets,--sheet(repeatable), and--interactive, and passed them through toMarkItDown.convert*(). - Refactored XLSX/XLS conversion to use
pd.ExcelFileand support listing/selecting sheets. - Updated CU CLI wiring test to assert the new kwargs are passed through.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/markitdown/src/markitdown/main.py | Adds new CLI options and passes them into conversion calls. |
| packages/markitdown/src/markitdown/converters/_xlsx_converter.py | Implements sheet listing/selection/interactive sheet picking for XLSX and XLS. |
| packages/markitdown/tests/test_cu_converter.py | Updates test expectations for new conversion kwargs and removes unused import. |
Suppressed comments (3)
packages/markitdown/src/markitdown/main.py:285
--list-sheetscurrently relies on the Excel converter printing sheet names, but the CLI still calls_handle_output(args, result)afterwards. This adds an extra blank line to stdout and will create/overwrite an empty--outputfile, which is surprising for a “list and exit” mode. Consider short-circuiting output handling when--list-sheetsis set.
_handle_output(args, result)
packages/markitdown/src/markitdown/converters/_xlsx_converter.py:201
- Same as above: normalize
sheet_selectionwhen it is provided as a string to avoid iterating characters during validation and to ensure the single-DataFrame fallback uses the full sheet name as the dict key.
# Handle --interactive
sheet_selection = kwargs.get("sheet_selection") or []
if kwargs.get("interactive"):
packages/markitdown/src/markitdown/converters/_xlsx_converter.py:227
- Same concern for
.xls: sheet-selection validation exceptions may be swallowed by the conversion pipeline and a later converter may produce output anyway, despite the user explicitly selecting sheets. Making these errors fatal likely requires changes outside this file.
for s in sheets_to_read:
if s not in sheet_names:
raise ValueError(f"Sheet not found: {s}")
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| result = markitdown.convert( | ||
| args.filename, stream_info=stream_info, keep_data_uris=args.keep_data_uris | ||
| args.filename, | ||
| stream_info=stream_info, | ||
| keep_data_uris=args.keep_data_uris, |
| # Handle --interactive | ||
| sheet_selection = kwargs.get("sheet_selection") or [] | ||
| if kwargs.get("interactive"): |
| for s in sheets_to_read: | ||
| if s not in sheet_names: | ||
| raise ValueError(f"Sheet not found: {s}") |
@microsoft-github-policy-service agree |
This pull request enhances the Excel file conversion capabilities in the
markitdownpackage by introducing new options for handling Excel sub-sheets. Users can now list available sheets, specify sheets to convert, or interactively select sheets. The changes also ensure that these options are integrated throughout the CLI, conversion logic, and tests.Excel sub-sheet selection and listing enhancements:
__main__.pyto allow users to list available sheets (--list-sheets), specify sheets to convert (--sheet), or interactively select sheets (--interactive).markitdown.convertto pass the new arguments (list_sheets,sheet_selection, andinteractive) from the CLI to the converter logic.Conversion logic updates:
pd.ExcelFilefor improved sheet handling,--list-sheetsis used,--interactiveis used,Testing updates:
markitdown.convert, ensuring that the CLI wiring is correct.Code cleanup: