Skip to main content
Glama

delete_sheet_rows

Remove specified rows from an Excel sheet by defining the start row and count. Streamlines data cleanup and restructuring within workbooks for improved organization.

Instructions

Delete one or more rows starting at the specified row.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
countNo
filepathYes
sheet_nameYes
start_rowYes

Implementation Reference

  • MCP tool handler for delete_sheet_rows, decorated with @mcp.tool() for registration and execution. Delegates to delete_rows helper.
    @mcp.tool() def delete_sheet_rows( filepath: str, sheet_name: str, start_row: int, count: int = 1 ) -> str: """Delete one or more rows starting at the specified row.""" try: full_path = get_excel_path(filepath) result = delete_rows(full_path, sheet_name, start_row, count) return result["message"] except (ValidationError, SheetError) as e: return f"Error: {str(e)}" except Exception as e: logger.error(f"Error deleting rows: {e}") raise
  • Core helper function implementing row deletion using openpyxl's worksheet.delete_rows method.
    def delete_rows(filepath: str, sheet_name: str, start_row: int, count: int = 1) -> Dict[str, Any]: """Delete one or more rows starting at the specified row.""" try: wb = load_workbook(filepath) if sheet_name not in wb.sheetnames: raise SheetError(f"Sheet '{sheet_name}' not found") worksheet = wb[sheet_name] # Validate parameters if start_row < 1: raise ValidationError("Start row must be 1 or greater") if count < 1: raise ValidationError("Count must be 1 or greater") if start_row > worksheet.max_row: raise ValidationError(f"Start row {start_row} exceeds worksheet bounds (max row: {worksheet.max_row})") worksheet.delete_rows(start_row, count) wb.save(filepath) return {"message": f"Deleted {count} row(s) starting at row {start_row} in sheet '{sheet_name}'"} except (ValidationError, SheetError) as e: logger.error(str(e)) raise except Exception as e: logger.error(f"Failed to delete rows: {e}") raise SheetError(str(e))
  • Tool registration via @mcp.tool() decorator in server.py.
    @mcp.tool() def delete_sheet_rows( filepath: str, sheet_name: str, start_row: int, count: int = 1 ) -> str: """Delete one or more rows starting at the specified row.""" try: full_path = get_excel_path(filepath) result = delete_rows(full_path, sheet_name, start_row, count) return result["message"] except (ValidationError, SheetError) as e: return f"Error: {str(e)}" except Exception as e: logger.error(f"Error deleting rows: {e}") raise

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