Skip to main content
Glama

write_data_to_excel

Write structured data directly to an Excel worksheet. Specify filepath, sheet name, data (as nested lists), and starting cell to populate Excel efficiently.

Instructions

Write data to Excel worksheet.
Excel formula will write to cell without any verification.

PARAMETERS:  
filepath: Path to Excel file
sheet_name: Name of worksheet to write to
data: List of lists containing data to write to the worksheet, sublists are assumed to be rows
start_cell: Cell to start writing to, default is "A1"

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dataYes
filepathYes
sheet_nameYes
start_cellNoA1

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • MCP tool handler and registration for 'write_data_to_excel'. Resolves filepath and calls the core write_data implementation.
    @mcp.tool()
    def write_data_to_excel(
        filepath: str,
        sheet_name: str,
        data: List[List],
        start_cell: str = "A1",
    ) -> str:
        """
        Write data to Excel worksheet.
        Excel formula will write to cell without any verification.
    
        PARAMETERS:  
        filepath: Path to Excel file
        sheet_name: Name of worksheet to write to
        data: List of lists containing data to write to the worksheet, sublists are assumed to be rows
        start_cell: Cell to start writing to, default is "A1"
      
        """
        try:
            full_path = get_excel_path(filepath)
            result = write_data(full_path, sheet_name, data, start_cell)
            return result["message"]
        except (ValidationError, DataError) as e:
            return f"Error: {str(e)}"
        except Exception as e:
            logger.error(f"Error writing data: {e}")
            raise
  • Core helper function 'write_data' that handles workbook loading, sheet management, data writing delegation, and saving.
    def write_data(
        filepath: str,
        sheet_name: Optional[str],
        data: Optional[List[List]],
        start_cell: str = "A1",
    ) -> Dict[str, str]:
        """Write data to Excel sheet with workbook handling
        
        Headers are handled intelligently based on context.
        """
        try:
            if not data:
                raise DataError("No data provided to write")
                
            wb = load_workbook(filepath)
    
            # If no sheet specified, use active sheet
            if not sheet_name:
                active_sheet = wb.active
                if active_sheet is None:
                    raise DataError("No active sheet found in workbook")
                sheet_name = active_sheet.title
            elif sheet_name not in wb.sheetnames:
                wb.create_sheet(sheet_name)
    
            ws = wb[sheet_name]
    
            # Validate start cell
            try:
                start_coords = parse_cell_range(start_cell)
                if not start_coords or not all(coord is not None for coord in start_coords[:2]):
                    raise DataError(f"Invalid start cell reference: {start_cell}")
            except ValueError as e:
                raise DataError(f"Invalid start cell format: {str(e)}")
    
            if len(data) > 0:
                _write_data_to_worksheet(ws, data, start_cell)
    
            wb.save(filepath)
            wb.close()
    
            return {"message": f"Data written to {sheet_name}", "active_sheet": sheet_name}
        except DataError as e:
            logger.error(str(e))
            raise
        except Exception as e:
            logger.error(f"Failed to write data: {e}")
            raise DataError(str(e))
  • Low-level helper that performs the actual cell-by-cell writing to the worksheet.
    def _write_data_to_worksheet(
        worksheet: Worksheet, 
        data: List[List], 
        start_cell: str = "A1",
    ) -> None:
        """Write data to worksheet with intelligent header handling"""
        try:
            if not data:
                raise DataError("No data provided to write")
    
            try:
                start_coords = parse_cell_range(start_cell)
                if not start_coords or not all(x is not None for x in start_coords[:2]):
                    raise DataError(f"Invalid start cell reference: {start_cell}")
                start_row, start_col = start_coords[0], start_coords[1]
            except ValueError as e:
                raise DataError(f"Invalid start cell format: {str(e)}")
    
            # Write data
            for i, row in enumerate(data):
                for j, val in enumerate(row):
                    worksheet.cell(row=start_row + i, column=start_col + j, value=val)
        except DataError as e:
            logger.error(str(e))
            raise
        except Exception as e:
            logger.error(f"Failed to write worksheet data: {e}")
            raise DataError(str(e))
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It mentions 'Excel formula will write to cell without any verification', hinting at potential data overwriting risks, but lacks details on permissions, error handling, or response format. This is inadequate for a mutation tool with zero annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with the core purpose, followed by a behavioral note and parameter list. It's efficient with minimal waste, though the parameter section could be integrated more smoothly into the flow.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the mutation nature, 0% schema coverage, and no annotations, the description is incomplete—it lacks error handling, output details, and sibling differentiation. However, an output schema exists, so return values needn't be explained, and it covers basic parameter semantics.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It lists all 4 parameters with brief explanations, adding meaning beyond the schema's titles. However, it doesn't specify formats (e.g., 'data' structure details) or constraints, leaving gaps in documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Write data to') and resource ('Excel worksheet'), distinguishing it from sibling tools like 'read_data_from_excel' and 'create_worksheet'. However, it doesn't specify what type of data is written beyond 'data', making it slightly less specific than ideal.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No explicit guidance on when to use this tool versus alternatives like 'format_range' or 'create_table' is provided. The description implies usage for writing raw data to a worksheet but doesn't mention prerequisites, exclusions, or comparisons to siblings.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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