add_sheet
Add a new sheet to a spreadsheet workbook, specifying name and position, with auto-generated options available.
Instructions
Add a new sheet to the workbook.
Returns the name of the newly created sheet. Not supported for CSV files.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file | Yes | Path to the spreadsheet file | |
| name | No | Name for the new sheet. Auto-generated if omitted. | |
| position | No | 1-based position to insert the sheet. Appended at the end if omitted. |
Implementation Reference
- The 'add_sheet' tool adds a new sheet to a workbook. It uses 'load_workbook' to load the file, 'wb.create_sheet' to add the sheet with a given title and index, and saves the changes.
@mcp.tool() def add_sheet( file: Annotated[str, Field(description="Path to the spreadsheet file")], name: Annotated[str | None, Field(description="Name for the new sheet. Auto-generated if omitted.")] = None, position: Annotated[int | None, Field(description="1-based position to insert the sheet. Appended at the end if omitted.")] = None, ) -> str: """Add a new sheet to the workbook. Returns the name of the newly created sheet. Not supported for CSV files. """ wb = load_workbook(file) ws = wb.create_sheet(title=name, index=position if position is None else position - 1) wb.save(file) return ws.title