set_cell_value
Assign values to specific cells in Excel spreadsheets by specifying file path, sheet name, cell location, and value. Supports strings, numbers, and boolean inputs for precise data entry.
Instructions
指定されたセルに値を設定します
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cell | Yes | セル位置。A1形式で指定(例: A1, B2, AA10, Z99)。範囲指定(A1:B2)は不可 | |
| filePath | Yes | 対象のExcelファイルの絶対パス | |
| sheetName | Yes | 対象のワークシート名。既存のワークシート名を指定してください | |
| value | Yes | セルに設定する値。文字列、数値、真偽値のいずれか |
Implementation Reference
- src/index.ts:231-247 (handler)Core handler function that validates the cell address, loads the Excel workbook using ExcelJS, retrieves the specified worksheet, sets the value in the target cell, saves the file, and returns a confirmation message.async function setCellValue(filePath: string, sheetName: string, cell: string, value: any): Promise<string> { try { validateCellAddress(cell); const workbook = await loadWorkbook(filePath); const worksheet = workbook.getWorksheet(sheetName); if (!worksheet) { throw new Error(`ワークシート '${sheetName}' が見つかりません。利用可能なシート: ${getSheetNames(workbook)}`); } worksheet.getCell(cell).value = value; await workbook.xlsx.writeFile(filePath); return `セル ${cell} に値 '${value}' を設定しました。`; } catch (error) { throw new McpError(ErrorCode.InternalError, `セル値設定エラー: ${error}`); } }
- src/index.ts:30-35 (schema)Zod schema defining the input parameters for the set_cell_value tool: filePath, sheetName, cell, and value.const SetCellValueSchema = z.object({ filePath: z.string().describe("対象のExcelファイルの絶対パス"), sheetName: z.string().describe("対象のワークシート名。既存のワークシート名を指定してください"), cell: z.string().describe("セル位置。A1形式で指定(例: A1, B2, AA10, Z99)。範囲指定(A1:B2)は不可"), value: z.union([z.string(), z.number(), z.boolean()]).describe("セルに設定する値。文字列、数値、真偽値のいずれか"), });
- src/index.ts:482-484 (registration)Tool registration in the ListTools response, specifying name, description, and input schema.name: "set_cell_value", description: "指定されたセルに値を設定します", inputSchema: zodToJsonSchema(SetCellValueSchema)
- src/index.ts:539-542 (handler)MCP tool handler wrapper that parses arguments using the schema and delegates to the core setCellValue function.set_cell_value: async (args: any) => { const { filePath, sheetName, cell, value } = SetCellValueSchema.parse(args); return await setCellValue(filePath, sheetName, cell, value); },
- src/index.ts:113-118 (helper)Helper function to validate cell address format (A1 style), used in setCellValue.function validateCellAddress(cell: string): void { const cellPattern = /^[A-Z]+[1-9]\d*$/; if (!cellPattern.test(cell)) { throw new Error(`無効なセル位置: '${cell}'。正しい形式: A1, B2, AA10など`); } }