Range

Represents one or more rectangular regions of cells in a given Sheet.

Constructors

Range

()

Methods

background

Gets or sets the background color of the cells in the range.

Parameters

value?

string

Any valid CSS color.

Returns

string

the current background color of the top-left cell of the range.

bold

Gets or sets the bold state of the cells in the range.

Parameters

value?

boolean

True to make the text bold; false otherwise.

Returns

boolean

the current bold state of the top-left cell of the range.

borderBottom

Gets or sets the state of the bottom border of the cells. If the range includes more than a single cell, the setting is applied to all cells.

Parameters

value?

CellBorder

The border configuration object. It may contain size and color keys.

Returns

CellBorder

the current value of the top-left cell of the range.

borderLeft

Gets or sets the state of the left border of the cells. If the range includes more than a single cell, the setting is applied to all cells.

Parameters

value?

CellBorder

The border configuration object. It may contain size and color keys.

Returns

CellBorder

the current value of the top-left cell of the range.

borderRight

Gets or sets the state of the right border of the cells. If the range includes more than a single cell, the setting is applied to all cells.

Parameters

value?

CellBorder

The border configuration object. It may contain size and color keys.

Returns

CellBorder

the current value of the top-left cell of the range.

borderTop

Gets or sets the state of the top border of the cells. If the range includes more than a single cell, the setting is applied to all cells.

Parameters

value?

CellBorder

The border configuration object. It may contain size and color keys.

Returns

CellBorder

the current value of the top-left cell of the range.

clear

Clears the contents of the range cells.

Parameters

value?

{ contentsOnly?: boolean; formatOnly: boolean; }

An object which may contain contentsOnly: true or formatOnly: true key values. Clearing the format will remove the cell formatting and visual styles. If a parameter is not passed, the method will clear both the cells values and the formatting.

color

Gets or sets the text color of the cells in the range.

Parameters

value?

string

Any valid CSS color.

Returns

string

the current text color of the top-left cell of the range.

enable

Gets or sets the disabled state of the cells in the range.

Parameters

value?

boolean

True to make the cell enabled; false to disable it.

Returns

boolean

the current disabled state of the top-left cell of the range.

fontFamily

Gets or sets the font family of the cells in the range.

Parameters

value?

string

The font family that should be set.

Returns

string

the font family of the top-left cell of the range.

fontSize

Gets or sets the font size of the cells in the range.

Parameters

value?

number

The font size (in pixels) that should be set.

Returns

number

the font size of the top-left cell of the range.

forEachCell

Executes a function for each cell in the range.

Parameters

value

(rowIndex: number, columnIndex: number, cellProperties: Cell) => void

The function that will be executed against every cell. The function receives the following parameters: rowIndex - the row index of the cell, columnIndex - the column index of the cell, cellProperties - the cell properties

format

Gets or sets the format of the cells.

Parameters

value?

string

The new format for the cells.

Returns

string

the format of the top-left cell of the range. When used as a setter, format returns the Range object to allow chained calls.

formula

Gets or sets the formula of the cells.

Parameters

value?

string

The new formula of the cell. The string may optionally start with =.

Returns

string

the formula of the top-left cell of the range.

input

Gets or sets the value of the cells. This is similar to value, but it parses the argument as if it was entered through the text box:

  • if it starts with = (equal sign), a formula is set. This may throw an error if the formula is syntactically invalid. Example: range("C1").input("=A1+B1").
  • if it looks like a number, a numeric value (not string) is set.
  • if it's true or false (case-insensitive) the respective boolean value is set.
  • if it's a Date object, or a string that can be parsed as a date, it is converted to the numerical representation of the date.
  • if it starts with ' (single quote), a string containing the rest of the characters is set. Example: range("A1").input("'TRUE") — sets the text "TRUE", not the boolean.
Parameters

value?

string | number | Date

The value to be set to the cells.

Returns

any

the current value of the top-left cell of the range.

italic

Gets or sets the italic state of the cells in the range.

Parameters

value?

boolean

True will make the text of the cells italic; false otherwise.

Returns

boolean

the current italic state of the top-left cell of the range.

Gets or sets the hyperlink of the cells in the range.

Parameters

value?

string

Pass a string (the URL) to create a hyperlink. Pass null to remove the link. Omit argument to get the existing URL, if any.

Returns

any

the current hyperlink attribute of the top-left cell of the range.

select

Sets the sheet selection to the range cells.

textAlign

Gets or sets the text alignment of the cells in the range.

Parameters

value?

string

One of the following values: "left", "center", "right" and "justify".

Returns

string

the current text alignment of the top-left cell of the range.

value

Gets or sets the value of the cells. If the cell has formula set, the value setting will clear it.

Parameters

value?

string | number | Date

The value to be set to the cells.

Returns

any

the current value of the top-left cell of the range.

verticalAlign

Gets or sets the vertical alignment of the cells in the range.

Parameters

value?

string

One of the following values: "top", "center" and "bottom".

Returns

string

the current text alignment of the top-left cell of the range.

wrap

Gets or sets the wrap of the range cells.

Parameters

value?

boolean

true if to enable wrapping, false otherwise.

Returns

boolean

the current wrap state of the top-left cell of the range.