Skip to main content
Glama
ishayoyo

Excel MCP Server

by ishayoyo

format_cells

Apply formatting to Excel cells including fonts, colors, borders, alignment, and number formats to improve data presentation and readability.

Instructions

Apply formatting to Excel cells (fonts, colors, borders, alignment)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesPath to the Excel file (.xlsx or .xls)
rangeYesCell range in A1 notation (e.g., "A1", "A1:C5", "B2:D10")
stylingYesFormatting options to apply
sheetNoSheet name (optional, defaults to first sheet)

Implementation Reference

  • The primary handler function for the format_cells tool. It loads an Excel workbook, parses the specified range using A1 notation, applies comprehensive cell styling including font properties, fill, borders, alignment, and number formatting to each cell in the range, then saves the modified workbook and returns a success response with details.
    async formatCells(args: ToolArgs): Promise<ToolResponse> {
      const { filePath, range, styling, sheet } = args;
      const ext = path.extname(filePath).toLowerCase();
      const absolutePath = path.resolve(filePath);
    
      if (ext !== '.xlsx' && ext !== '.xls') {
        throw new Error('Cell formatting only works with Excel files (.xlsx or .xls)');
      }
    
      try {
        await fs.access(absolutePath);
      } catch {
        throw new Error(`File not found: ${filePath}`);
      }
    
      // Read existing workbook
      const workbook = new ExcelJS.Workbook();
      await workbook.xlsx.readFile(absolutePath);
    
      // Get the worksheet
      const worksheet = sheet ? workbook.getWorksheet(sheet) : workbook.getWorksheet(1);
      if (!worksheet) {
        throw new Error(`Sheet "${sheet || 'first sheet'}" not found`);
      }
    
      // Parse range (e.g., "A1:C5" or "B2")
      let startCell: { row: number; col: number };
      let endCell: { row: number; col: number };
    
      if (range.includes(':')) {
        const [start, end] = range.split(':');
        const startParsed = parseA1Notation(start);
        const endParsed = parseA1Notation(end);
        // Convert to 1-based indexing for ExcelJS
        startCell = { row: startParsed.row + 1, col: startParsed.col + 1 };
        endCell = { row: endParsed.row + 1, col: endParsed.col + 1 };
      } else {
        const parsed = parseA1Notation(range);
        // Convert to 1-based indexing for ExcelJS
        startCell = endCell = { row: parsed.row + 1, col: parsed.col + 1 };
      }
    
      let formattedCells = 0;
    
      // Apply formatting to the range
      for (let row = startCell.row; row <= endCell.row; row++) {
        for (let col = startCell.col; col <= endCell.col; col++) {
          const cell = worksheet.getCell(row, col);
    
          // Apply font styling
          if (styling.font) {
            const fontStyle: any = {};
            if (styling.font.bold !== undefined) fontStyle.bold = styling.font.bold;
            if (styling.font.italic !== undefined) fontStyle.italic = styling.font.italic;
            if (styling.font.underline !== undefined) fontStyle.underline = styling.font.underline;
            if (styling.font.size !== undefined) fontStyle.size = styling.font.size;
            if (styling.font.color !== undefined) fontStyle.color = { argb: styling.font.color };
            if (styling.font.name !== undefined) fontStyle.name = styling.font.name;
    
            cell.font = { ...cell.font, ...fontStyle };
          }
    
          // Apply fill (background color)
          if (styling.fill) {
            if (styling.fill.color) {
              cell.fill = {
                type: 'pattern',
                pattern: styling.fill.pattern || 'solid',
                fgColor: { argb: styling.fill.color }
              };
            }
          }
    
          // Apply borders
          if (styling.border) {
            const borderStyle: any = {};
            const borderConfig = {
              style: styling.border.style || 'thin',
              color: { argb: styling.border.color || 'FF000000' }
            };
    
            if (styling.border.top !== false) borderStyle.top = borderConfig;
            if (styling.border.bottom !== false) borderStyle.bottom = borderConfig;
            if (styling.border.left !== false) borderStyle.left = borderConfig;
            if (styling.border.right !== false) borderStyle.right = borderConfig;
    
            cell.border = { ...cell.border, ...borderStyle };
          }
    
          // Apply alignment
          if (styling.alignment) {
            const alignmentStyle: any = {};
            if (styling.alignment.horizontal) alignmentStyle.horizontal = styling.alignment.horizontal;
            if (styling.alignment.vertical) alignmentStyle.vertical = styling.alignment.vertical;
            if (styling.alignment.wrapText !== undefined) alignmentStyle.wrapText = styling.alignment.wrapText;
            if (styling.alignment.textRotation !== undefined) alignmentStyle.textRotation = styling.alignment.textRotation;
    
            cell.alignment = { ...cell.alignment, ...alignmentStyle };
          }
    
          // Apply number format
          if (styling.numberFormat) {
            cell.numFmt = styling.numberFormat;
          }
    
          formattedCells++;
        }
      }
    
      // Save the workbook
      await workbook.xlsx.writeFile(absolutePath);
    
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify({
              success: true,
              filePath: absolutePath,
              sheetName: worksheet.name,
              range,
              cellsFormatted: formattedCells,
              stylingApplied: Object.keys(styling),
            }, null, 2),
          },
        ],
      };
    }
  • Utility function parseA1Notation converts A1 cell notation (e.g., 'A1', 'C5') to zero-based {row, col} coordinates. Critically used in formatCells to parse start/end ranges for applying formatting.
    export function parseA1Notation(a1: string): CellAddress {
      const match = a1.match(/^([A-Z]+)(\d+)$/);
      if (!match) {
        throw new Error(`Invalid A1 notation: ${a1}`);
      }
    
      const col = match[1].split('').reduce((acc, char) => {
        return acc * 26 + char.charCodeAt(0) - 'A'.charCodeAt(0) + 1;
      }, 0) - 1;
    
      const row = parseInt(match[2]) - 1;
    
      return { row, col };
    }
Behavior2/5

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

With no annotations provided, the description carries full burden but only states what the tool does, not how it behaves. It doesn't disclose that this is a mutation operation (modifies files), potential side effects (overwrites existing formatting), error conditions, or response format. For a tool that modifies Excel files, this is a significant gap in behavioral context.

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

Conciseness5/5

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

Extremely concise single sentence with zero waste. Every word earns its place: 'Apply formatting' (action), 'to Excel cells' (target), and parenthetical examples of formatting types. No redundant information or unnecessary elaboration.

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

Completeness2/5

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

For a mutation tool with no annotations and no output schema, the description is insufficient. It doesn't explain what happens after formatting is applied (success/failure indicators), whether changes are saved automatically, or any behavioral constraints. The 100% schema coverage helps with parameters, but overall context for a file-modifying operation is inadequate.

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 100%, so the schema fully documents all 4 parameters and their nested properties. The description adds minimal value beyond the schema by listing formatting categories (fonts, colors, borders, alignment) which are already detailed in the schema. Baseline 3 is appropriate when schema does the heavy lifting.

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 ('Apply formatting') and resource ('to Excel cells'), with specific formatting types listed (fonts, colors, borders, alignment). It distinguishes from siblings like 'write_file' or 'get_cell' by focusing on styling, but doesn't explicitly differentiate from all possible formatting-related tools that might exist.

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 guidance is provided about when to use this tool versus alternatives. There's no mention of prerequisites (e.g., file must exist), when not to use it, or how it relates to sibling tools like 'write_file' (which might also handle formatting). The description assumes the user knows when formatting is needed.

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

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/ishayoyo/excel-mcp'

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