export_to_csv
Convert Excel worksheet data to CSV format using file paths and sheet names for accurate and structured data export.
Instructions
ワークシートをCSVファイルにエクスポートします
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| csvPath | Yes | CSVファイルの出力パス | |
| filePath | Yes | Excelファイルのパス(既存ファイル) | |
| sheetName | Yes | ワークシート名(既存シート) |
Implementation Reference
- src/index.ts:447-460 (handler)The core handler function that loads the Excel workbook, retrieves the specified worksheet, and exports it to a CSV file using ExcelJS.async function exportToCSV(filePath: string, sheetName: string, csvPath: string): Promise<string> { try { const workbook = await loadWorkbook(filePath); const worksheet = workbook.getWorksheet(sheetName); if (!worksheet) { throw new Error(`ワークシート '${sheetName}' が見つかりません。`); } await workbook.csv.writeFile(csvPath, { sheetName }); return `ワークシート '${sheetName}' をCSVファイル '${csvPath}' にエクスポートしました。`; } catch (error) { throw new McpError(ErrorCode.InternalError, `CSV出力エラー: ${error}`); } }
- src/index.ts:94-98 (schema)Zod schema defining the input parameters for the export_to_csv tool: filePath, sheetName, and csvPath.const ExportToCSVSchema = z.object({ filePath: z.string().describe("Excelファイルのパス(既存ファイル)"), sheetName: z.string().describe("ワークシート名(既存シート)"), csvPath: z.string().describe("CSVファイルの出力パス"), });
- src/index.ts:517-520 (registration)Registration of the export_to_csv tool in the ListTools response, including name, description, and input schema.name: "export_to_csv", description: "ワークシートをCSVファイルにエクスポートします", inputSchema: zodToJsonSchema(ExportToCSVSchema) }
- src/index.ts:567-570 (registration)The tool handler registration in the toolImplementations map, which parses args with the schema and delegates to the exportToCSV function.export_to_csv: async (args: any) => { const { filePath, sheetName, csvPath } = ExportToCSVSchema.parse(args); return await exportToCSV(filePath, sheetName, csvPath); }