ApiRange

new ApiRange()

Class representing a range.

Properties

Name Type Description
Row number

Returns the row number for the selected cell.

Col number

Returns the column number for the selected cell.

Rows ApiRange

Returns the ApiRange object that represents the rows of the specified range.

Cols ApiRange

Returns the ApiRange object that represents the columns of the specified range.

Cells ApiRange

Returns a Range object that represents all the cells in the specified range or a specified cell.

Count number

Returns the rows or columns count.

Address string

Returns the range address.

Value string

Returns a value from the first cell of the specified range or sets it to this cell.

Formula string

Returns a formula from the first cell of the specified range or sets it to this cell.

Value2 string

Returns the value2 (value without format) from the first cell of the specified range or sets it to this cell.

Text string

Returns the text from the first cell of the specified range or sets it to this cell.

FontColor ApiColor

Sets the text color to the current cell range with the previously created color object.

Hidden boolean

Returns or sets the value hiding property.

ColumnWidth number

Returns or sets the width of all the columns in the specified range measured in points.

Width number

Returns a value that represents the range width measured in points.

RowHeight number

Returns or sets the height of the first row in the specified range measured in points.

Height number

Returns a value that represents the range height measured in points.

FontSize number

Sets the font size to the characters of the current cell range.

FontName string

Sets the specified font family as the font name for the current cell range.

AlignVertical 'center' | 'bottom' | 'top' | 'distributed' | 'justify'

Sets the text vertical alignment to the current cell range.

AlignHorizontal 'left' | 'right' | 'center' | 'justify'

Sets the text horizontal alignment to the current cell range.

Bold boolean

Sets the bold property to the text characters from the current cell or cell range.

Italic boolean

Sets the italic property to the text characters in the current cell or cell range.

Underline 'none' | 'single' | 'singleAccounting' | 'double' | 'doubleAccounting'

Sets the type of underline applied to the font.

Strikeout boolean

Sets a value that indicates whether the contents of the current cell or cell range are displayed struck through.

WrapText boolean

Returns the information about the wrapping cell style or specifies whether the words in the cell must be wrapped to fit the cell size or not.

FillColor ApiColor | 'No Fill'

Returns or sets the background color of the current cell range.

NumberFormat string

Sets a value that represents the format code for the object.

MergeArea ApiRange

Returns the cell or cell range from the merge area.

Worksheet ApiWorksheet

Returns the ApiWorksheet object that represents the worksheet containing the specified range.

DefName ApiName

Returns the ApiName object.

Comments ApiComment | null

Returns the ApiComment collection that represents all the comments from the specified worksheet.

Orientation 'xlDownward' | 'xlHorizontal' | 'xlUpward' | 'xlVertical'

Sets an angle to the current cell range.

Areas ApiAreas

Returns a collection of the areas.

Characters ApiCharacters

Returns the ApiCharacters object that represents a range of characters within the object text. Use the ApiCharacters object to format characters within a text string.

Methods

Name Description
AddComment

Adds a comment to the current range.

AutoFit

Changes the width of the columns or the height of the rows in the range to achieve the best fit.

Clear

Clears the current range.

Copy

Copies a range to the specified range.

Delete

Deletes the Range object.

End

Returns a Range object that represents the end in the specified direction in the specified range.

Find

Finds specific information in the current range.

FindNext

Continues a search that was begun with the ApiRange#Find method. Finds the next cell that matches those same conditions and returns the ApiRange object that represents that cell. This does not affect the selection or the active cell.

FindPrevious

Continues a search that was begun with the ApiRange#Find method. Finds the previous cell that matches those same conditions and returns the ApiRange object that represents that cell. This does not affect the selection or the active cell.

ForEach

Executes a provided function once for each cell.

GetAddress

Returns the range address.

GetAreas

Returns a collection of the ranges.

GetCells

Returns a Range object that represents all the cells in the specified range or a specified cell.

GetCharacters

Returns the ApiCharacters object that represents a range of characters within the object text. Use the ApiCharacters object to format characters within a text string.

GetClassType

Returns a type of the ApiRange class.

GetCol

Returns a column number for the selected cell.

GetCols

Returns a Range object that represents the columns in the specified range.

GetColumnWidth

Returns the column width value.

GetComment

Returns the ApiComment object of the current range.

GetCount

Returns the rows or columns count.

GetDefName

Returns the ApiName object of the current range.

GetFillColor

Returns the background color for the current cell range. Returns 'No Fill' when the color of the background in the cell / cell range is null.

GetFormula

Returns a formula of the specified range.

GetHidden

Returns the value hiding property. The specified range must span an entire column or row.

GetNumberFormat

Returns a value that represents the format code for the current range.

GetOrientation

Returns the current range angle.

GetRow

Returns a row number for the selected cell.

GetRowHeight

Returns the row height value.

GetRows

Returns a Range object that represents the rows in the specified range. If the specified row is outside the Range object, a new Range will be returned that represents the cells between the columns of the original range in the specified row.

GetText

Returns the text of the specified range.

GetValue

Returns a value of the specified range.

GetValue2

Returns the Value2 property (value without format) of the specified range.

GetWorksheet

Returns the Worksheet object that represents the worksheet containing the specified range. It will be available in the read-only mode.

GetWrapText

Returns the information about the wrapping cell style.

Insert

Inserts a cell or a range of cells into the worksheet or macro sheet and shifts other cells away to make space.

Merge

Merges the selected cell range into a single cell or a cell row.

Paste

Pastes the Range object to the specified range.

Replace

Replaces specific information to another one in a range.

Select

Selects the current range.

SetAlignHorizontal

Sets the horizontal alignment of the text in the current cell range.

SetAlignVertical

Sets the vertical alignment of the text in the current cell range.

SetBold

Sets the bold property to the text characters in the current cell or cell range.

SetBorders

Sets the border to the cell / cell range with the parameters specified.

SetColumnWidth

Sets the width of all the columns in the current range. One unit of column width is equal to the width of one character in the Normal style. For proportional fonts, the width of the character 0 (zero) is used.

SetFillColor

Sets the background color to the current cell range with the previously created color object. Sets 'No Fill' when previously created color object is null.

SetFontColor

Sets the text color to the current cell range with the previously created color object.

SetFontName

Sets the specified font family as the font name for the current cell range.

SetFontSize

Sets the font size to the characters of the current cell range.

SetHidden

Sets the value hiding property. The specified range must span an entire column or row.

SetItalic

Sets the italic property to the text characters in the current cell or cell range.

SetNumberFormat

Specifies whether a number in the cell should be treated like number, currency, date, time, etc. or just like text.

SetOffset

Sets the cell offset.

SetOrientation

Sets an angle to the current cell range.

SetRowHeight

Sets the row height value.

SetSort

Sorts the cells in the given range by the parameters specified in the request.

SetStrikeout

Specifies that the contents of the cell / cell range are displayed with a single horizontal line through the center of the contents.

SetUnderline

Specifies that the contents of the current cell / cell range are displayed along with a line appearing directly below the character.

SetValue

Sets a value to the current cell or cell range.

SetWrap

Specifies whether the words in the cell must be wrapped to fit the cell size or not.

UnMerge

Splits the selected merged cell range into the single cells.

Example

Copy code
builder.CreateFile("xlsx");
var oWorksheet = Api.GetActiveSheet();
var oRange = oWorksheet.GetRange("A1");
oRange.SetValue(2);
oRange.AddComment("This is just a number.");
oWorksheet.GetRange("B1").SetValue(2);
oWorksheet.GetRange("C1").SetValue("1");
oWorksheet.GetRange("A3").SetValue("2+2=");
oWorksheet.GetRange("B3").SetValue("=SUM(A1:B1)");
oRange = oWorksheet.GetRange("A1:B1");
oRange.ForEach(function (range) {
    var sValue = range.GetValue();
    if (sValue != "1") {
        range.SetBold(true);
    }
});
var sAddress = oWorksheet.GetRange("A1").GetAddress(true, true, "xlA1", false);
oWorksheet.GetRange("A2").SetValue("Address: " + sAddress);
var sClassType = oRange.GetClassType();
oWorksheet.GetRange('A7').SetValue("Class type: " + sClassType);
oRange = oWorksheet.GetRange("A4:B4");
oRange.SetValue("1");
oRange.Clear();
oWorksheet.GetRange("A5").SetValue("The range A4:B4 was just cleared.");
oRange = oWorksheet.GetRange("C6:D7");
oRange.End("xlToLeft").SetFillColor(Api.CreateColorFromRGB(255, 213, 191));
oRange.GetCells(2, 1).SetFillColor(Api.CreateColorFromRGB(255, 213, 191));
oRange = oWorksheet.GetRange("D9").GetCol();
oWorksheet.GetRange("C7").SetValue(oRange.toString());
oRange = oWorksheet.GetRange("A1:C3");
oRange.GetCols(3).SetFillColor(Api.CreateColorFromRGB(255, 213, 191));
var nWidth = oWorksheet.GetRange("A1").GetColumnWidth();
oWorksheet.GetRange("A8").SetValue("Width: " + nWidth);
oWorksheet.GetRange("A9").SetValue("Comment: " + oWorksheet.GetRange("A1").GetComment().GetText());
var nCount = oWorksheet.GetRange("A9:C9").GetCount();
oWorksheet.GetRange("A10").SetValue("Count: " + nCount);
Api.AddDefName("numbers", "Sheet1!$A$1:$B$1");
var oDefName = oWorksheet.GetRange("A1:B1").GetDefName("numbers");
oWorksheet.GetRange("A11").SetValue("DefName of the A1:B1 range: " + oDefName.GetName());
oRange = oWorksheet.GetRange("E1");
oRange.SetFillColor(Api.CreateColorFromRGB(255, 213, 191));
oRange.SetValue("This is the cell with a color set to its background.");
var oFillColor = oRange.GetFillColor();
oWorksheet.GetRange("E3").SetValue("This is another cell with the same color set to its background");
oWorksheet.GetRange("E3").SetFillColor(oFillColor);
oWorksheet.GetRange("13:14").SetHidden(true);
var bHidden = oWorksheet.GetRange("13:14").GetHidden();
oWorksheet.GetRange("A15").SetValue("The A13:A14 range is hidden: " + bHidden);
builder.SaveFile("xlsx", "ApiRange.xlsx");
builder.CloseFile();

Resulting document