Skip to main content
Glama

create_worksheet

Add a new worksheet to an Excel workbook by specifying the file path and sheet name. Streamline workbook organization and data management with this tool on the Excel MCP Server.

Instructions

Create new worksheet in workbook.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filepathYes
sheet_nameYes

Implementation Reference

  • MCP tool handler and registration for 'create_worksheet'. Resolves the full file path using get_excel_path, imports and calls the create_sheet helper from workbook module, handles errors, and returns the result message.
    @mcp.tool() def create_worksheet(filepath: str, sheet_name: str) -> str: """Create new worksheet in workbook.""" try: full_path = get_excel_path(filepath) from excel_mcp.workbook import create_sheet as create_worksheet_impl result = create_worksheet_impl(full_path, sheet_name) return result["message"] except (ValidationError, WorkbookError) as e: return f"Error: {str(e)}" except Exception as e: logger.error(f"Error creating worksheet: {e}") raise
  • Core helper function implementing the worksheet creation logic using openpyxl. Loads the workbook, checks if the sheet already exists, creates a new sheet if not, saves the workbook, and returns a success message.
    def create_sheet(filepath: str, sheet_name: str) -> dict: """Create a new worksheet in the workbook if it doesn't exist.""" try: wb = load_workbook(filepath) # Check if sheet already exists if sheet_name in wb.sheetnames: raise WorkbookError(f"Sheet {sheet_name} already exists") # Create new sheet wb.create_sheet(sheet_name) wb.save(filepath) wb.close() return {"message": f"Sheet {sheet_name} created successfully"} except WorkbookError as e: logger.error(str(e)) raise except Exception as e: logger.error(f"Failed to create sheet: {e}") raise WorkbookError(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