Skip to main content
Glama

excel_find_replace

Locate and substitute specific text within Excel worksheets to update financial data, correct errors, or modify content efficiently.

Instructions

Find and replace text in a worksheet

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
matchCaseNo
matchEntireCellNo
replaceTextYes
searchTextYes
worksheetNameYes

Implementation Reference

  • MCP tool handler for 'excel_find_replace' that calls ExcelManager.findAndReplace and returns result
    handler: async (args: any): Promise<ToolResult> => { try { const count = await excelManager.findAndReplace( args.worksheetName, args.searchText, args.replaceText, { matchCase: args.matchCase, matchEntireCell: args.matchEntireCell } ); return { success: true, data: { replacements: count }, message: `Replaced ${count} instances` }; } catch (error) { return { success: false, error: error instanceof Error ? error.message : String(error) }; } }
  • Input schema for the excel_find_replace tool defining required and optional parameters
    inputSchema: { type: "object", properties: { worksheetName: { type: "string" }, searchText: { type: "string" }, replaceText: { type: "string" }, matchCase: { type: "boolean", default: false }, matchEntireCell: { type: "boolean", default: false } }, required: ["worksheetName", "searchText", "replaceText"] },
  • src/index.ts:32-44 (registration)
    Registration of all tools including excelTools (which contains excel_find_replace) into the MCP server's allTools array used for listTools and callTool
    const allTools = [ ...excelTools, ...financialTools, ...rentalTools, ...expenseTools, ...reportingTools, ...cashFlowTools, ...taxTools, ...analyticsTools, ...chartTools, ...complianceTools, ...propertyTools, ];
  • Core helper method implementing the find and replace functionality using ExcelJS by iterating over worksheet cells and performing regex-based replacements
    async findAndReplace( worksheetName: string, searchText: string | RegExp, replaceText: string, options?: { matchCase?: boolean; matchEntireCell?: boolean } ): Promise<number> { if (!this.workbook) { throw new Error('No workbook is currently open'); } const worksheet = this.workbook.getWorksheet(worksheetName); if (!worksheet) { throw new Error(`Worksheet "${worksheetName}" not found`); } let replacementCount = 0; worksheet.eachRow((row) => { row.eachCell((cell) => { if (cell.value && typeof cell.value === 'string') { let matches = false; if (searchText instanceof RegExp) { matches = searchText.test(cell.value); if (matches) { cell.value = cell.value.replace(searchText, replaceText); replacementCount++; } } else { if (options?.matchEntireCell) { matches = options?.matchCase ? cell.value === searchText : cell.value.toLowerCase() === searchText.toLowerCase(); if (matches) { cell.value = replaceText; replacementCount++; } } else { const regex = new RegExp( searchText.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), options?.matchCase ? 'g' : 'gi' ); const newValue = cell.value.replace(regex, replaceText); if (newValue !== cell.value) { cell.value = newValue; replacementCount++; } } } } }); }); return replacementCount; }

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

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