add_formula
Insert formulas into specified Excel cells using file path, sheet name, and cell position. Automates Excel calculations for data manipulation and analysis.
Instructions
セルに数式を追加します
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cell | Yes | セル位置(例: A1) | |
| filePath | Yes | Excelファイルのパス | |
| formula | Yes | 数式(=SUM(A1:A10)など、=で始まる) | |
| sheetName | Yes | ワークシート名 |
Implementation Reference
- src/index.ts:404-419 (handler)Implements the core logic for adding a formula to a specific cell in an Excel worksheet using ExcelJS.async function addFormula(filePath: string, sheetName: string, cell: string, formula: string): Promise<string> { try { const workbook = await loadWorkbook(filePath); const worksheet = workbook.getWorksheet(sheetName); if (!worksheet) { throw new Error(`ワークシート '${sheetName}' が見つかりません。`); } worksheet.getCell(cell).value = { formula: formula }; await workbook.xlsx.writeFile(filePath); return `セル ${cell} に数式 '${formula}' を設定しました。`; } catch (error) { throw new McpError(ErrorCode.InternalError, `数式追加エラー: ${error}`); } }
- src/index.ts:87-92 (schema)Zod schema for validating the input parameters of the add_formula tool.const AddFormulaSchema = z.object({ filePath: z.string().describe("Excelファイルのパス"), sheetName: z.string().describe("ワークシート名"), cell: z.string().describe("セル位置(例: A1)"), formula: z.string().describe("数式(=SUM(A1:A10)など、=で始まる)"), });
- src/index.ts:559-561 (registration)Registers the add_formula tool in the toolImplementations map by providing a wrapper that parses arguments and delegates to the main handler function.add_formula: async (args: any) => { const { filePath, sheetName, cell, formula } = AddFormulaSchema.parse(args); return await addFormula(filePath, sheetName, cell, formula);
- src/index.ts:507-509 (registration)Registers the add_formula tool metadata (name, description, schema) in the ListTools response.name: "add_formula", description: "セルに数式を追加します", inputSchema: zodToJsonSchema(AddFormulaSchema)