New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

SpreadsheetRange Object

This article explains the methods of the SpreadsheetRange client-side object and provides examples on its usage.

The following example demonstrates two approaches for acquisition of a SpreadsheetRange reference, which can be used to manipulate the cell(s) state further.

JavaScript

function getRange() {
	var spreadsheet = $find("<%= RadSpreadSheet1.ClientID %>");
	var activeSheet = spreadsheet.get_activeSheet();
	var singleCellRange = activeSheet.get_range("A1")  
	var mutliCellRange = activeSheet.get_range("A1:B3"); // using A1 Notation
}

The following table lists the methods of the client-side SpreadsheetRange object:

NameParametersReturn TypeDescription
get_enablednoneboolGets the disabled state of the cells in the range.
set_enabledboolnoneSets the disabled state of the cells in the range. (see Example 1)
set_filterbool/Object/ArraynoneEnables/disables or sets the filter for a given range. (see Example 2)
hasFilternoneboolReturns true if the sheet of the range has filter enabled.
get_isSortablenoneboolReturns true if a range can be sorted.
get_isFilterablenoneboolReturns true if a range can be filtered.
mergenonenoneMerges the range cells into a single merged cell. If the range already includes a merged cell, they are merged, too. (see Example 3)
unmergenonenoneUn-merges any merged cells which are included in the range.
selectnonenoneSets the sheet selection to the range cells.
fillFromSpreadsheetRange/stringnoneFills a range with values inferred from a source range. This method employs some heuristics similar to what Excel's auto-filling algorithm does when you select a range of cells and drag the bottom-right handle. The range to be filled is the current object, and you must pass a source range containing data as first argument.
clearnone/objectnoneClears the contents of the range cells.
clearFilterArray/intnoneClears the set filters for the given column(s). The indices is relative to the beginning of the range. (see Example 4)
get_borderBottomColornonestringGets the color of the bottom border of the cells.
set_borderBottomColorstringnoneSets the color of the bottom border of the cells. If the range includes more than a single cell, the setting is applied to all cells. The color may be set to any valid CSS color. (see Example 5)
get_borderBottomSizenoneintGets the size of the bottom border of the cells.
set_borderBottomSizeintnoneSets the size of the bottom border of the cells. If the range includes more than a single cell, the setting is applied to all cells. The method accepts any valid Length value. (see Example 6)
get_borderLeftColornonestringGets the color of the left border of the cells.
set_borderLeftColorstringnoneSets the color of the left border of the cells. If the range includes more than a single cell, the setting is applied to all cells. The color may be set to any valid CSS color.
get_borderLeftSizenoneintGets the size of the left border of the cells.
set_borderLeftSizeintnoneSets the size of the left border of the cells. If the range includes more than a single cell, the setting is applied to all cells. The method accepts any valid Length value.
get_borderRightColornonestringGets the color of the right border of the cells.
set_borderRightColorstringnoneSets the color of the right border of the cells. If the range includes more than a single cell, the setting is applied to all cells. The color may be set to any valid CSS color.
get_borderRightSizenoneintGets the size of the right border of the cells.
set_borderRightSizeintnoneSets the size of the right border of the cells. If the range includes more than a single cell, the setting is applied to all cells. The method accepts any valid Length value.
get_borderTopColornonestringGets the color of the top border of the cells.
set_borderTopColorstringnoneSets the color of the top border of the cells. If the range includes more than a single cell, the setting is applied to all cells. The color may be set to any valid CSS color.
get_borderTopSizenoneintGets the size of the top border of the cells.
set_borderTopSizeintnoneSets the size of the top border of the cells. If the range includes more than a single cell, the setting is applied to all cells. The method accepts any valid Length value.
get_backgroundnonestringGets the background color of the cells in the range.
set_backgroundstringnoneSets the background color of the cells in the range. The background may be set to any valid CSS color. (see Example 7)
get_boldnoneboolGets the bold state of the cells in the range.
set_boldboolnoneSets the bold state of the cells in the range. (see Example 8)
get_colornonestringGets the current text color of the top-left cell of the range.
set_colorstringnoneSets the text color of the range. The color may be set to any valid CSS color.
get_fontFamilynonestringGets the font family of the top-left cell of the range.
set_fontFamilystringnoneSets the font family of the cells in the range.
get_fontSizenoneintGets the font size of the top-left cell of the range.
set_fontSizeintnoneSets the font size (in pixels) of the cells in the range.
get_formatnonestringGets the format (string) of the top-left cell of the range
set_formatstringnoneSets the format of the cells in the range. (see Example 9)
get_formulanonestringGets the formula of the cells
set_formulastringnoneSets the formula of the cells. The string that the method accepts may optionally start with =. (see Example 10)
get_inputnonestringGets the value of the cells. If the Range includes more than one cell - returns the top-left cell input value of the range.
set_inputstringnoneSets the value of the cells. This is similar to value, but it parses the argument as if it was entered through the text box. Using the method you can set text, formula, number, boolean or Date. (see Example 11)
get_italicnoneboolGets the italic state of the cells in the range.
set_italicboolnoneSets the italic state of the cells in the range.
get_selectionsnonearray of objectsGets the selections in the range. (see Example 12)
get_textAlignnonestringGets the text alignment of the cells in the range. Returns one of the following values: left, center, right and justify.
set_textAlignstringnoneSets the text alignment of the cells in the range. Accepts one of the following values: left, center, right and justify.
get_underlinenoneboolGets the underline state of the cells in the range.
set_underlineboolnoneSets the underline state of the cells in the range.
get_valuenonestring/int/DateGets the value of the cells.
set_valuestring/int/DatenoneSets the value of the cells.
get_valuesnonearray of arraysGets the values of the range cells.
set_valuesarray of arraysnoneSets the values of the range cells. The argument should be an array of arrays which match the dimensions of the range. (see Example 13)
get_validationnoneobjectGets the current validation of the top-left cell of the range.
set_validationobjectnoneSets the validation of the cells. The object that is passed to the method may contain type, comparerType, dataType, from, to, allowNulls, messageTemplate and titleTemplate keys. (see Example 14)
get_verticalAlignnonestringGets current vertical text alignment of the top-left cell of the range. Returns one of the following values: top, center and bottom.
set_verticalAlignstringnoneSets the vertical alignment of the cells in the range. Accepts one of the following values: top, center and bottom.
get_wrapnoneboolGets the wrap of the range cells.
set_wrapboolnoneSets the wrap of the range cells. (see Example 15)

Example 1: Demonstrates the usage of the set_enabled method

JavaScript
function enableDisableRange() {
    var spreadsheet = $find("<%= RadSpreadsheet1.ClientID %>");
    var activeSheet = spreadsheet.get_activeSheet();
    var range = activeSheet.get_range("A1:B3");
    if (range.get_enabled()) {
        range.set_enabled(false);
    }
    else {
        range.set_enabled(true);
    }
}

Example 2: Demonstrates the usage of the set_filter method

JavaScript
function addFilter() {
    var spreadsheet = $find("<%= RadSpreadsheet1.ClientID %>");
    var activeSheet = spreadsheet.get_activeSheet();
    var range = activeSheet.get_range("A1:B3");
    var filter = new kendo.spreadsheet.DynamicFilter({ type: "today" });
    range.set_filter([{ column: 0, filter: filter }]);
}

Example 3: Demonstrates the usage of the merge method

JavaScript
function mergeRange() {
    var spreadsheet = $find("<%= RadSpreadsheet1.ClientID %>");
    var activeSheet = spreadsheet.get_activeSheet();
    var range = activeSheet.get_range("A1:B3");
    range.merge();
}

Example 4: Demonstrates the usage of the set_filter method

JavaScript
function addFilter() {
    var spreadsheet = $find("<%= RadSpreadsheet1.ClientID %>");
    var activeSheet = spreadsheet.get_activeSheet();
    var range = activeSheet.get_range("A1:B3");
    var filter = new kendo.spreadsheet.DynamicFilter({ type: "today" });
    range.set_filter([{ column: 0, filter: filter }]);
}

Example 5: Demonstrates the usage of the set_borderBottomColor method

JavaScript
function colorRangeBottomBorder() {
    var spreadsheet = $find("<%= RadSpreadsheet1.ClientID %>");
    var activeSheet = spreadsheet.get_activeSheet();
    var range = activeSheet.get_range("A1:B3");
    range.set_borderBottomColor("#0000ff");
}

Example 6: Demonstrates the usage of the set_borderBottomSize method

JavaScript
function setRangeBottomBorderSize() {
    var spreadsheet = $find("<%= RadSpreadsheet1.ClientID %>");
    var activeSheet = spreadsheet.get_activeSheet();
    var range = activeSheet.get_range("A1:B3");
    range.set_borderBottomSize(3);
}

Example 7: Demonstrates the usage of the set_background method

JavaScript
function changeRangeBackground() {
    var spreadsheet = $find("<%= RadSpreadsheet1.ClientID %>");
    var activeSheet = spreadsheet.get_activeSheet();
    var range = activeSheet.get_range("A1:B3");
    range.set_background("#c0c0c0");
}

Example 8: Demonstrates the usage of the set_bold method

JavaScript
function changeRangeFontWeight() {
    var spreadsheet = $find("<%= RadSpreadsheet1.ClientID %>");
    var activeSheet = spreadsheet.get_activeSheet();
    var range = activeSheet.get_range("A1:B3");
    range.set_bold(true);
}

Example 9: Demonstrates the usage of the set_format method

JavaScript
function setRangeFormat() {
    var spreadsheet = $find("<%= RadSpreadsheet1.ClientID %>");
    var activeSheet = spreadsheet.get_activeSheet();
    var range = activeSheet.get_range("A1:B3");
    range.set_format("00.000");
}

Example 10: Demonstrates the usage of the set_formula method

JavaScript
function setRangeFormula() {
    var spreadsheet = $find("<%= RadSpreadsheet1.ClientID %>");
    var activeSheet = spreadsheet.get_activeSheet();
	var rangeA1 = activeSheet.get_range("A1");
	rangeA1.set_input("100");
    var rangeA2 = activeSheet.get_range("A2");
    range2.set_formula("A1*2");
}

Example 11: Demonstrates the usage of the set_input method

JavaScript
function setRangeInput() {
    var spreadsheet = $find("<%= RadSpreadsheet1.ClientID %>");
    var activeSheet = spreadsheet.get_activeSheet();
	var range = activeSheet.get_range("A1");
	range.set_input("100");
}

Example 12: Demonstrates the usage of the get_selections method

JavaScript
function OnClientChange(sender, args) {
    var range = args.get_range();
    var selections = range.get_selections();

    var row = selections[0].bottomRightCell.row;
}

Example 13: Demonstrates the usage of the set_values method

JavaScript
function setRangeValues() {
    var spreadsheet = $find("<%= RadSpreadsheet1.ClientID %>");
    var activeSheet = spreadsheet.get_activeSheet();
    var range = activeSheet.get_range("A1:B3");
    var newValues = [[1, 2], [12, 28], [33, 5]];
    range.set_values(newValues);
}

Example 14: Demonstrates the usage of the set_validation method

JavaScript
function setRangeValidation() {
    var spreadsheet = $find("<%= RadSpreadsheet1.ClientID %>");
    var activeSheet = spreadsheet.get_activeSheet();
    var range = activeSheet.get_range("A1");
    range.set_value(4);
    var validation = {
        from: "1",
        to: "2",
        comparerType: "between",
        dataType: "number",
        messageTemplate: "Number should match the validation."
    };

    range.set_validation(validation);
}

Example 15: Demonstrates the usage of the set_wrap method

JavaScript
function setRangeWrap() {
    var spreadsheet = $find("<%= RadSpreadsheet1.ClientID %>");
    var activeSheet = spreadsheet.get_activeSheet();
    var range = activeSheet.get_range("A1");
    range.set_wrap(true);
}
Not finding the help you need?
Contact Support