clear_range
Clear cell values in a spreadsheet range while preserving row and column structure. Use this tool to remove data from specific cells without deleting rows or columns.
Instructions
Clear all cell values in a range without removing rows or columns.
Sets every cell in the range to null. Row/column structure is preserved.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file | Yes | Path to the spreadsheet file | |
| range_str | Yes | Range to clear in A1 notation, e.g. 'A1:D10'. Only values are removed. | |
| sheet | No | Sheet name. Defaults to the first sheet if omitted. |
Implementation Reference
- The clear_range tool handler, which clears cell values in a specified range and saves the spreadsheet.
@mcp.tool() def clear_range( file: Annotated[str, Field(description="Path to the spreadsheet file")], range_str: Annotated[str, Field(description="Range to clear in A1 notation, e.g. 'A1:D10'. Only values are removed.")], sheet: Annotated[str | None, Field(description="Sheet name. Defaults to the first sheet if omitted.")] = None, ) -> str: """Clear all cell values in a range without removing rows or columns. Sets every cell in the range to null. Row/column structure is preserved. """ wb = load_workbook(file) ws = _resolve_sheet(wb, sheet) min_col, min_row, max_col, max_row = parse_range(range_str) for r in range(min_row, max_row + 1): for c in range(min_col, max_col + 1): ws.set_cell(r, c, None) wb.save(file) return f"Cleared range {range_str}"