Skip to main content
Glama

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
NameRequiredDescriptionDefault
filepathYes
sheet_nameYes

Implementation Reference

  • 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
  • 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))

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/haris-musa/excel-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server