read_excel_by_sheet_index
Extract data from a specific sheet in Excel files by specifying its index number. Reads the first sheet by default when no index is provided.
Instructions
Read content from a specific sheet by index in Excel (xlsx) files. Reads first sheet (index 0) if sheet_index not provided.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | Path to the Excel file | |
| sheet_index | No | Index of the sheet to read (optional, defaults to 0) |
Implementation Reference
- Executes the tool logic: retrieves sheet by index (default 0), validates index, reads all rows into list of lists with string values, stores in result dict.elif name == "read_excel_by_sheet_index": # Get sheet by index, default to 0 if not specified sheet_index = arguments.get("sheet_index", 0) if sheet_index < 0 or sheet_index >= len(workbook.sheetnames): raise ValueError(f"Sheet index {sheet_index} is out of range") sheet_name = workbook.sheetnames[sheet_index] sheet = workbook[sheet_name] sheet_data = [] for row in sheet.rows: row_data = [str(cell.value) if cell.value is not None else "" for cell in row] sheet_data.append(row_data) result[sheet_name] = sheet_data
- Input schema for the tool: requires file_path (string), optional sheet_index (integer >=0).types.Tool( name="read_excel_by_sheet_index", description="Read content from a specific sheet by index in Excel (xlsx) files. Reads first sheet (index 0) if sheet_index not provided.", inputSchema={ "type": "object", "properties": { "file_path": { "type": "string", "description": "Path to the Excel file" }, "sheet_index": { "type": "integer", "description": "Index of the sheet to read (optional, defaults to 0)", "minimum": 0 } }, "required": ["file_path"] } )
- src/excel_reader_server/server.py:18-71 (registration)The tool is registered by including it in the list returned by @server.list_tools() handler.return [ types.Tool( name="read_excel", description="Read content from Excel (xlsx) files", inputSchema={ "type": "object", "properties": { "file_path": { "type": "string", "description": "Path to the Excel file" } }, "required": ["file_path"] } ), types.Tool( name="read_excel_by_sheet_name", description="Read content from a specific sheet by name in Excel (xlsx) files. Reads first sheet if sheet_name not provided.", inputSchema={ "type": "object", "properties": { "file_path": { "type": "string", "description": "Path to the Excel file" }, "sheet_name": { "type": "string", "description": "Name of the sheet to read (optional, defaults to first sheet)" } }, "required": ["file_path"] } ), types.Tool( name="read_excel_by_sheet_index", description="Read content from a specific sheet by index in Excel (xlsx) files. Reads first sheet (index 0) if sheet_index not provided.", inputSchema={ "type": "object", "properties": { "file_path": { "type": "string", "description": "Path to the Excel file" }, "sheet_index": { "type": "integer", "description": "Index of the sheet to read (optional, defaults to 0)", "minimum": 0 } }, "required": ["file_path"] } ) ]