rename_sheet
Change the name of a sheet in a spreadsheet file by specifying the current name and desired new name.
Instructions
Rename an existing sheet in the workbook.
Returns the new sheet name on success.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file | Yes | Path to the spreadsheet file | |
| old_name | Yes | Current name of the sheet to rename | |
| new_name | Yes | New name for the sheet |
Implementation Reference
- Handler function for the rename_sheet tool which renames a sheet in a workbook.
def rename_sheet( file: Annotated[str, Field(description="Path to the spreadsheet file")], old_name: Annotated[str, Field(description="Current name of the sheet to rename")], new_name: Annotated[str, Field(description="New name for the sheet")], ) -> str: """Rename an existing sheet in the workbook. Returns the new sheet name on success. """ wb = load_workbook(file) ws = wb.get_sheet(old_name) ws.title = new_name wb.save(file) return new_name