find_data
Locate specific values within Excel worksheets by specifying file path, sheet name, and search value to streamline data retrieval.
Instructions
ワークシート内で指定された値を検索します
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | Excelファイルのパス | |
| searchValue | Yes | 検索する値 | |
| sheetName | Yes | ワークシート名 |
Implementation Reference
- src/index.ts:422-444 (handler)The main handler function that loads the Excel workbook, iterates through rows and cells in the specified sheet to find exact matches for the searchValue, and returns a string listing the matching cell addresses.async function findData(filePath: string, sheetName: string, searchValue: any): Promise<string> { try { const workbook = await loadWorkbook(filePath); const worksheet = workbook.getWorksheet(sheetName); if (!worksheet) { throw new Error(`ワークシート '${sheetName}' が見つかりません。`); } const results: string[] = []; worksheet.eachRow((row, rowNumber) => { row.eachCell((cell, colNumber) => { if (cell.value === searchValue) { const cellAddress = worksheet.getCell(rowNumber, colNumber).address; results.push(cellAddress); } }); }); return `値 '${searchValue}' が見つかったセル: ${results.join(', ')}`; } catch (error) { throw new McpError(ErrorCode.InternalError, `データ検索エラー: ${error}`); } }
- src/index.ts:81-85 (schema)Zod schema defining the input parameters for the find_data tool: filePath (string), sheetName (string), searchValue (string or number).const FindDataSchema = z.object({ filePath: z.string().describe("Excelファイルのパス"), sheetName: z.string().describe("ワークシート名"), searchValue: z.union([z.string(), z.number()]).describe("検索する値"), });
- src/index.ts:563-566 (registration)Tool implementation wrapper in the toolImplementations map that parses input arguments using FindDataSchema and delegates to the findData handler function. This is invoked by the CallToolRequestSchema handler.find_data: async (args: any) => { const { filePath, sheetName, searchValue } = FindDataSchema.parse(args); return await findData(filePath, sheetName, searchValue); },
- src/index.ts:511-515 (registration)Registration of the find_data tool in the ListToolsRequestSchema response, providing name, description, and input schema for tool discovery.{ name: "find_data", description: "ワークシート内で指定された値を検索します", inputSchema: zodToJsonSchema(FindDataSchema) },