excel_create_workbook
Create Excel workbooks with structured worksheets and financial data for analysis, reporting, and accounting workflows.
Instructions
Create a new Excel workbook with specified worksheets and data
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| worksheets | Yes |
Implementation Reference
- src/excel/excel-manager.ts:28-58 (handler)Core handler implementation in ExcelManager class that creates a new Excel workbook using ExcelJS, adds worksheets from input data, sets columns, and populates cells supporting formulas and styles.async createWorkbook(worksheets: WorksheetData[]): Promise<void> { this.workbook = new ExcelJS.Workbook(); for (const wsData of worksheets) { const worksheet = this.workbook.addWorksheet(wsData.name); if (wsData.columns) { worksheet.columns = wsData.columns; } wsData.data.forEach((row, rowIndex) => { row.forEach((cell, colIndex) => { const cellRef = worksheet.getCell(rowIndex + 1, colIndex + 1); if (typeof cell === 'object' && cell !== null && !(cell instanceof Date)) { const cellData = cell as CellValue; if (cellData.formula) { cellRef.value = { formula: cellData.formula }; } else { cellRef.value = cellData.value; } if (cellData.style) { Object.assign(cellRef, { style: cellData.style }); } } else { cellRef.value = cell; } }); }); } }
- src/tools/excel-tools.ts:12-42 (schema)Input schema defining the structure for worksheets array, each with name, data (2D array), and optional columns.inputSchema: { type: "object", properties: { worksheets: { type: "array", items: { type: "object", properties: { name: { type: "string" }, data: { type: "array", items: { type: "array" } }, columns: { type: "array", items: { type: "object", properties: { header: { type: "string" }, key: { type: "string" }, width: { type: "number" } } } } }, required: ["name", "data"] } } }, required: ["worksheets"] },
- src/tools/excel-tools.ts:9-57 (registration)Tool registration object defining name, description, inputSchema, and handler that delegates to ExcelManager.createWorkbook.{ name: "excel_create_workbook", description: "Create a new Excel workbook with specified worksheets and data", inputSchema: { type: "object", properties: { worksheets: { type: "array", items: { type: "object", properties: { name: { type: "string" }, data: { type: "array", items: { type: "array" } }, columns: { type: "array", items: { type: "object", properties: { header: { type: "string" }, key: { type: "string" }, width: { type: "number" } } } } }, required: ["name", "data"] } } }, required: ["worksheets"] }, handler: async (args: any): Promise<ToolResult> => { try { await excelManager.createWorkbook(args.worksheets); return { success: true, message: `Created workbook with ${args.worksheets.length} worksheets` }; } catch (error) { return { success: false, error: error instanceof Error ? error.message : String(error) }; } } },
- src/index.ts:32-44 (registration)Main MCP server tool registration where excelTools (containing excel_create_workbook) is spread into the complete allTools array used for tool listing and execution.const allTools = [ ...excelTools, ...financialTools, ...rentalTools, ...expenseTools, ...reportingTools, ...cashFlowTools, ...taxTools, ...analyticsTools, ...chartTools, ...complianceTools, ...propertyTools, ];
- src/tools/excel-tools.ts:6-6 (helper)Instantiation of the shared ExcelManager instance used by all Excel tools, including createWorkbook.const excelManager = new ExcelManager();