delete_rows
Remove specified rows from a spreadsheet file to clean up data or reorganize content, shifting remaining rows upward automatically.
Instructions
Delete one or more rows, shifting remaining rows up.
All data in the deleted rows is permanently removed.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file | Yes | Path to the spreadsheet file | |
| row | Yes | 1-based index of the first row to delete | |
| count | No | Number of consecutive rows to delete starting from row | |
| sheet | No | Sheet name. Defaults to the first sheet if omitted. |
Implementation Reference
- The 'delete_rows' MCP tool handler, which loads the workbook, resolves the sheet, calls 'delete_rows' on the worksheet, and saves the file.
@mcp.tool() def delete_rows( file: Annotated[str, Field(description="Path to the spreadsheet file")], row: Annotated[int, Field(description="1-based index of the first row to delete")], count: Annotated[int, Field(description="Number of consecutive rows to delete starting from row")] = 1, sheet: Annotated[str | None, Field(description="Sheet name. Defaults to the first sheet if omitted.")] = None, ) -> str: """Delete one or more rows, shifting remaining rows up. All data in the deleted rows is permanently removed. """ wb = load_workbook(file) ws = _resolve_sheet(wb, sheet) ws.delete_rows(row, count) wb.save(file) return f"Deleted {count} rows starting at row {row}"