Skip to main content
Glama

excel_merge_files

Combine multiple Excel files into a single workbook for consolidated financial analysis, expense tracking, and automated reporting.

Instructions

Merge multiple Excel files into one workbook

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputFilesYes
outputPathYes

Implementation Reference

  • Core handler logic for merging multiple Excel files: creates new workbook, copies all worksheets from each input file with prefixed names, preserves styles and formulas, saves to output path.
    async mergeFiles(filePaths: string[], outputPath: string): Promise<void> { const mergedWorkbook = new ExcelJS.Workbook(); for (const filePath of filePaths) { const sourceWorkbook = new ExcelJS.Workbook(); await sourceWorkbook.xlsx.readFile(filePath); sourceWorkbook.worksheets.forEach(sourceSheet => { const newSheetName = `${path.basename(filePath, '.xlsx')}_${sourceSheet.name}`; const targetSheet = mergedWorkbook.addWorksheet(newSheetName); sourceSheet.eachRow((row, rowNumber) => { const newRow = targetSheet.getRow(rowNumber); row.eachCell((cell, colNumber) => { const newCell = newRow.getCell(colNumber); newCell.value = cell.value; newCell.style = cell.style; if ((cell as any).formula) { (newCell as any).formula = (cell as any).formula; } }); }); targetSheet.columns = sourceSheet.columns; }); } await mergedWorkbook.xlsx.writeFile(outputPath); }
  • MCP tool handler function that invokes ExcelManager.mergeFiles with input parameters and handles success/error response.
    handler: async (args: any): Promise<ToolResult> => { try { await excelManager.mergeFiles(args.inputFiles, args.outputPath); return { success: true, message: `Merged ${args.inputFiles.length} files into ${args.outputPath}` }; } catch (error) { return { success: false, error: error instanceof Error ? error.message : String(error) }; } }
  • Input schema defining array of input file paths and output file path.
    inputSchema: { type: "object", properties: { inputFiles: { type: "array", items: { type: "string" } }, outputPath: { type: "string" } }, required: ["inputFiles", "outputPath"]
  • Tool registration in excelTools array, including name, description, schema, and handler.
    { name: "excel_merge_files", description: "Merge multiple Excel files into one workbook", inputSchema: { type: "object", properties: { inputFiles: { type: "array", items: { type: "string" } }, outputPath: { type: "string" } }, required: ["inputFiles", "outputPath"] }, handler: async (args: any): Promise<ToolResult> => { try { await excelManager.mergeFiles(args.inputFiles, args.outputPath); return { success: true, message: `Merged ${args.inputFiles.length} files into ${args.outputPath}` }; } catch (error) { return { success: false, error: error instanceof Error ? error.message : String(error) }; } } },

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