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
| Name | Required | Description | Default |
|---|---|---|---|
| inputFiles | Yes | ||
| outputPath | Yes |
Implementation Reference
- src/excel/excel-manager.ts:351-379 (handler)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); }
- src/tools/excel-tools.ts:372-385 (handler)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) }; } }
- src/tools/excel-tools.ts:361-370 (schema)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"]
- src/tools/excel-tools.ts:358-386 (registration)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) }; } } },