Skip to main content
Glama

read_excel_by_sheet_index

Extract data from a specific sheet in Excel (xlsx) files using its index. Defaults to the first sheet if no index is provided, returning structured JSON output for efficient data processing and analysis.

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
NameRequiredDescriptionDefault
file_pathYesPath to the Excel file
sheet_indexNoIndex of the sheet to read (optional, defaults to 0)

Implementation Reference

  • Handler logic for the 'read_excel_by_sheet_index' tool: retrieves the sheet by index (default 0), validates index, loads sheet data by iterating rows and converting cell values to strings, 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"] } )
  • Registration of the tool via the list_tools handler, which returns the Tool object including schema for read_excel_by_sheet_index among others.
    @server.list_tools() async def handle_list_tools() -> list[types.Tool]: """ List available tools. Each tool specifies its arguments using JSON Schema validation. """ 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"] } ) ]

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/softgridinc-pte-ltd/mcp-excel-reader-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server