Get Excel Used Range
Get Excel Used Range
Section titled “Get Excel Used Range”Type: excel-get-used-range · Package: Excel Activities v1.0.6 · Output: Dictionary
Returns the dimensions of the area that holds data in a sheet (the “used range”). It tells you how many rows and columns there are and where they start and end, without reading all the content. Useful to know the size of the data before processing it, or to build a dynamic range.
How it works
Section titled “How it works”It computes the smallest rectangle that covers every cell with content (values or formulas) and returns a dictionary with its metrics. Cells that only have formatting (color, borders) don’t count. Accepts session or path — see the two modes.
Read-only: in fast mode it does not modify the file.
Required parameters
Section titled “Required parameters”None — but you must set session or path (or be inside the body of an Excel Open).
Optional parameters
Section titled “Optional parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
session | ZoanExcelSession | — | Excel Open session (instead of path). |
path | string | — | Path to the .xlsx (required if there is no session). The file must exist. |
sheet | string | int | — | Sheet name or 1-based index. If omitted, the first sheet. |
Output
Section titled “Output”Returns a Dictionary with these exact keys:
| Key | Type | Description |
|---|---|---|
address | string | Address of the used range, e.g. "A1:F120" (no $ or sheet name). |
rows | int | Number of rows in the range. |
columns | int | Number of columns in the range. |
firstRow | int | Number of the first row (1-based). |
firstColumn | int | Number of the first column (1-based: A = 1). |
lastRow | int | Number of the last row. |
lastColumn | int | Number of the last column. |
Empty sheet: address is null and every other key is 0 (it also logs a warning). Check it with dim["rows"] == 0.
Common errors
Section titled “Common errors”| Message | Cause and fix |
|---|---|
'session' or 'path' is required. | Neither session nor path is set. |
File not found. | path does not exist. |
There isn't a worksheet named '…'. | No sheet has that name. |
There isn't a worksheet associated with that position. | The sheet index does not exist (or the name is just a number and was taken as an index). |
Example
Section titled “Example”Get Excel Used Range path = asset("data.xlsx") → output: dimLog message = "The sheet has " + dim["rows"] + " rows and " + dim["columns"] + " columns"Read only columns A to C, down to the last row with data:
Get Excel Used Range path = asset("data.xlsx") sheet = "Sales" → output: dimRead Excel Range path = asset("data.xlsx") sheet = "Sales" range = "A1:C" + dim["lastRow"] → output: salesRelated activities
Section titled “Related activities”- Read Excel Sheet — read the data area into a DataTable.
- Get Excel Sheet Names — list the workbook’s sheets.