Skip to main content
Glama

delete_sheet_columns

Remove specified columns from an Excel sheet by defining the starting column and count. Simplify data cleanup and reorganization for improved spreadsheet management.

Instructions

Delete one or more columns starting at the specified column.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
countNo
filepathYes
sheet_nameYes
start_colYes

Implementation Reference

  • MCP tool handler function for 'delete_sheet_columns' that resolves file path and delegates to core delete_cols implementation, handles errors and returns message.
    @mcp.tool() def delete_sheet_columns( filepath: str, sheet_name: str, start_col: int, count: int = 1 ) -> str: """Delete one or more columns starting at the specified column.""" try: full_path = get_excel_path(filepath) result = delete_cols(full_path, sheet_name, start_col, count) return result["message"] except (ValidationError, SheetError) as e: return f"Error: {str(e)}" except Exception as e: logger.error(f"Error deleting columns: {e}") raise
  • Core helper function that performs the actual column deletion using openpyxl: loads workbook, validates inputs, calls worksheet.delete_cols(start_col, count), saves the file, and returns success message.
    def delete_cols(filepath: str, sheet_name: str, start_col: int, count: int = 1) -> Dict[str, Any]: """Delete one or more columns starting at the specified column.""" 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_col < 1: raise ValidationError("Start column must be 1 or greater") if count < 1: raise ValidationError("Count must be 1 or greater") if start_col > worksheet.max_column: raise ValidationError(f"Start column {start_col} exceeds worksheet bounds (max column: {worksheet.max_column})") worksheet.delete_cols(start_col, count) wb.save(filepath) return {"message": f"Deleted {count} column(s) starting at column {start_col} in sheet '{sheet_name}'"} except (ValidationError, SheetError) as e: logger.error(str(e)) raise except Exception as e: logger.error(f"Failed to delete columns: {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