get_merged_cells
Identify merged cells in a specific Excel worksheet by providing the filepath and sheet name to analyze cell ranges effectively.
Instructions
Get merged cells in a worksheet.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filepath | Yes | ||
| sheet_name | Yes |
Implementation Reference
- src/excel_mcp/server.py:470-480 (handler)MCP tool handler and registration for 'get_merged_cells'. Loads the workbook path, calls the helper function get_merged_ranges, converts result to string, and handles exceptions.@mcp.tool() def get_merged_cells(filepath: str, sheet_name: str) -> str: """Get merged cells in a worksheet.""" try: full_path = get_excel_path(filepath) return str(get_merged_ranges(full_path, sheet_name)) except (ValidationError, SheetError) as e: return f"Error: {str(e)}" except Exception as e: logger.error(f"Error getting merged cells: {e}") raise
- src/excel_mcp/sheet.py:246-259 (helper)Core helper function that implements the logic to retrieve all merged cell ranges from a worksheet using openpyxl's merged_cells attribute.def get_merged_ranges(filepath: str, sheet_name: str) -> list[str]: """Get merged cells in a worksheet.""" try: wb = load_workbook(filepath) if sheet_name not in wb.sheetnames: raise SheetError(f"Sheet '{sheet_name}' not found") worksheet = wb[sheet_name] return [str(merged_range) for merged_range in worksheet.merged_cells.ranges] except SheetError as e: logger.error(str(e)) raise except Exception as e: logger.error(f"Failed to get merged cells: {e}") raise SheetError(str(e))