get_sheet_dimensions
Retrieve the row and column count of data in a spreadsheet sheet to determine its size and structure for processing or analysis.
Instructions
Get the dimensions of the used range in a sheet.
Returns {"rows": N, "columns": M} where N is the number of the last used row and M is the number of the last used column. Both are 0 for an empty sheet.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file | Yes | Path to the spreadsheet file | |
| sheet | No | Sheet name. Defaults to the first sheet if omitted. |
Implementation Reference
- Implementation of the 'get_sheet_dimensions' tool, which uses 'load_workbook' and '_resolve_sheet' helpers to retrieve dimensions from the SpreadsheetSheet object.
def get_sheet_dimensions( file: Annotated[str, Field(description="Path to the spreadsheet file")], sheet: Annotated[str | None, Field(description="Sheet name. Defaults to the first sheet if omitted.")] = None, ) -> dict: """Get the dimensions of the used range in a sheet. Returns {"rows": N, "columns": M} where N is the number of the last used row and M is the number of the last used column. Both are 0 for an empty sheet. """ wb = load_workbook(file) ws = _resolve_sheet(wb, sheet) return { "rows": ws.max_row, "columns": ws.max_column, }