Range

Range class

Encapsulates the object that represents a range of cells within a spreadsheet. The Range class denotes a region of Excel spreadsheet. With this, you can format and set value of the range. And you can simply copy range of Excel too.

Methods

NameDescription
addHyperlink(address, textToDisplay, screenTip)Adds a hyperlink to a specified cell or a range of cells.
applyStyle(style, flag)Applies formats for a whole range. Each cell in this range will contains a Style object. So this is a memory-consuming m
autoFill(target)Automaticall fill the target range.
autoFill(target, autoFillType)Automaticall fill the target range.
clear()
clearComments()
clearContents()
clearFormats()
clearHyperlinks()
copy(range, options)Copying the range with paste special options.
copy(range)Copies data (including formulas), formatting, drawing objects etc. from a source range.
copyData(range)Copies cell data (including formulas) from a source range.
copyStyle(range)Copies style settings from a source range.
copyValue(range)Copies cell value from a source range.
get(rowOffset, columnOffset)Gets Cell object in this range.
getAddress()Gets address of the range.
getCellOrNull(rowOffset, columnOffset)Gets Cell object or null in this range.
getColumnCount()Gets the count of columns in the range.
getColumnWidth()Sets or gets the column width of this range
getCurrentRegion()Returns a Range object that represents the current region. The current region is a range bounded by any combination of b
getEntireColumn()Gets a Range object that represents the entire column (or columns) that contains the specified range.
getEntireRow()Gets a Range object that represents the entire row (or rows) that contains the specified range.
getFirstColumn()Gets the index of the first column of the range.
getFirstRow()Gets the index of the first row of the range.
getHeight()Gets the width of a range in points.
getHyperlinks()Gets all hyperlink in the range.
getLeft()Gets the distance, in points, from the left edge of column A to the left edge of the range.
getName()Gets or sets the name of the range. Named range is supported. For example, range.Name = “Sheet1!MyRange”;
getOffset(rowOffset, columnOffset)Gets Range range by offset.
getRefersTo()Gets the range’s refers to.
getRowCount()Gets the count of rows in the range.
getRowHeight()Sets or gets the height of rows in this range
getTop()Gets the distance, in points, from the top edge of row 1 to the top edge of the range.
getValue()Gets and sets the value of the range. If the range contains multiple cells, the returned/applied object should be Object
getWidth()Gets the width of a range in points.
getWorksheet()Gets the Worksheetobject which contains this range.
intersect(range)Returns a Range object that represents the rectangular intersection of two ranges. If the two ranges are not intersected
isBlank()Indicates whether the range contains values.
isIntersect(range)Indicates whether the range is intersect. If the two ranges area not in the same worksheet ,return false.
iterator()Gets the enumerator for cells in this Range. When traversing elements by the returned Enumerator, the cells collection s
merge()Combines a range of cells into a single cell. Reference the merged cell via the address of the upper-left cell in the ra
moveTo(destRow, destColumn)Move the current range to the dest range.
putValue(stringValue, isConverted, setStyle)Puts a value into the range, if appropriate the value will be converted to other data type and cell’s number format will
setColumnWidth()Sets or gets the column width of this range
setInsideBorders(borderEdge, lineStyle, borderColor)Set inside borders of the range.
setName()Gets or sets the name of the range. Named range is supported. For example, range.Name = “Sheet1!MyRange”;
setOutlineBorder(borderEdge, borderStyle, borderColor)Sets outline border around a range of cells.
setOutlineBorder(borderEdge, borderStyle, borderColor)Sets outline border around a range of cells.
setOutlineBorders(borderStyle, borderColor)Sets the outline borders around a range of cells with same border style and color.
setOutlineBorders(borderStyle, borderColor)Sets the outline borders around a range of cells with same border style and color.
setOutlineBorders(borderStyles, borderColors)Sets out line borders around a range of cells. Both the length of borderStyles and borderStyles must be 4. The order of
setRowHeight()Sets or gets the height of rows in this range
setStyle(style, explicitFlag)Apply the cell style.
setStyle(style)Sets the style of the range.
setValue()Gets and sets the value of the range. If the range contains multiple cells, the returned/applied object should be Object
toHtml(saveOptions)Convert the range to html .
toImage(options)Converts the range to image.
toJson(options)Convert the range to JSON value.
toString()Returns a string represents the current Range object.
transpose()Transpose (rotate) data from rows to columns or vice versa.
unMerge()Unmerges merged cells of this range.
union(range)Returns the union of two ranges. NOTE: This method is now obsolete. Instead, please use Range.UnionRanges() method. This
unionRang(range)Returns the union result of two ranges. NOTE: This method is now obsolete. Instead, please use Range.UnionRanges() metho
unionRanges(ranges)Returns the union result of two ranges.

Adds a hyperlink to a specified cell or a range of cells.

ParameterTypeDescription
addressStringAddress of the hyperlink.
textToDisplayStringThe text to be displayed for the specified hyperlink.
screenTipStringThe screenTip text for the specified hyperlink.

Returns: Hyperlink — Hyperlink Hyperlink object.

applyStyle(style, flag)

Applies formats for a whole range. Each cell in this range will contains a Style object. So this is a memory-consuming method. Please use it carefully.

ParameterTypeDescription
styleStyleThe style object which will be applied.
flagStyleFlagFlags which indicates applied formatting properties.

autoFill(target)

Automaticall fill the target range.

ParameterTypeDescription
targetRangethe target range.

autoFill(target, autoFillType)

Automaticall fill the target range.

ParameterTypeDescription
targetRangeThe targed range.
autoFillTypeNumberAutoFillType

clear()

clearComments()

clearContents()

clearFormats()

copy(range, options)

Copying the range with paste special options.

ParameterTypeDescription
rangeRangeThe source range.
optionsPasteOptionsThe paste special options.

copy(range)

Copies data (including formulas), formatting, drawing objects etc. from a source range.

ParameterTypeDescription
rangeRangeSource

copyData(range)

Copies cell data (including formulas) from a source range.

ParameterTypeDescription
rangeRangeSource

copyStyle(range)

Copies style settings from a source range.

ParameterTypeDescription
rangeRangeSource

copyValue(range)

Copies cell value from a source range.

ParameterTypeDescription
rangeRangeSource

get(rowOffset, columnOffset)

Gets Cell object in this range.

ParameterTypeDescription
rowOffsetNumberRow offset in this range, zero based.
columnOffsetNumberColumn offset in this range, zero based.

Returns: Cell — Cell Cell object.

getAddress()

Gets address of the range.

getCellOrNull(rowOffset, columnOffset)

Gets Cell object or null in this range.

ParameterTypeDescription
rowOffsetNumberRow offset in this range, zero based.
columnOffsetNumberColumn offset in this range, zero based.

Returns: Cell — Cell Cell object.

getColumnCount()

Gets the count of columns in the range.

getColumnWidth()

Sets or gets the column width of this range

getCurrentRegion()

Returns a Range object that represents the current region. The current region is a range bounded by any combination of blank rows and blank columns.

getEntireColumn()

Gets a Range object that represents the entire column (or columns) that contains the specified range.

getEntireRow()

Gets a Range object that represents the entire row (or rows) that contains the specified range.

getFirstColumn()

Gets the index of the first column of the range.

getFirstRow()

Gets the index of the first row of the range.

getHeight()

Gets the width of a range in points.

Gets all hyperlink in the range.

getLeft()

Gets the distance, in points, from the left edge of column A to the left edge of the range.

getName()

Gets or sets the name of the range. Named range is supported. For example, range.Name = “Sheet1!MyRange”;

getOffset(rowOffset, columnOffset)

Gets Range range by offset.

ParameterTypeDescription
rowOffsetNumberRow offset in this range, zero based.
columnOffsetNumberColumn offset in this range, zero based.

Returns: Range — Range

getRefersTo()

Gets the range’s refers to.

getRowCount()

Gets the count of rows in the range.

getRowHeight()

Sets or gets the height of rows in this range

getTop()

Gets the distance, in points, from the top edge of row 1 to the top edge of the range.

getValue()

Gets and sets the value of the range. If the range contains multiple cells, the returned/applied object should be Object[][].

getWidth()

Gets the width of a range in points.

getWorksheet()

Gets the Worksheetobject which contains this range.

intersect(range)

Returns a Range object that represents the rectangular intersection of two ranges. If the two ranges are not intersected, returns null.

ParameterTypeDescription
rangeRangeThe intersecting range.

Returns: Range — Range Returns a Range object

isBlank()

Indicates whether the range contains values.

Returns: boolean — boolean

isIntersect(range)

Indicates whether the range is intersect. If the two ranges area not in the same worksheet ,return false.

ParameterTypeDescription
rangeRangeThe range.

Returns: boolean — boolean Whether the range is intersect.

iterator()

Gets the enumerator for cells in this Range. When traversing elements by the returned Enumerator, the cells collection should not be modified(such as operations that will cause new Cell/Row be instantiated or existing Cell/Row be deleted). Otherwise the enumerator may not be able to traverse all cells correctly(some elements may be traversed repeatedly or skipped).@return {Iterator} The cells enumerator

merge()

Combines a range of cells into a single cell. Reference the merged cell via the address of the upper-left cell in the range.

moveTo(destRow, destColumn)

Move the current range to the dest range.

ParameterTypeDescription
destRowNumberThe start row of the dest range.
destColumnNumberThe start column of the dest range.

putValue(stringValue, isConverted, setStyle)

Puts a value into the range, if appropriate the value will be converted to other data type and cell’s number format will be reset.

ParameterTypeDescription
stringValueStringInput value
isConvertedbooleanTrue: converted to other data type if appropriate.
setStylebooleanTrue: set the number format to cell’s style when converting to other data type

setColumnWidth()

Sets or gets the column width of this range

setInsideBorders(borderEdge, lineStyle, borderColor)

Set inside borders of the range.

ParameterTypeDescription
borderEdgeNumberBorderType
lineStyleNumberCellBorderType
borderColorCellsColorThe color of the border.

setName()

Gets or sets the name of the range. Named range is supported. For example, range.Name = “Sheet1!MyRange”;

setOutlineBorder(borderEdge, borderStyle, borderColor)

Sets outline border around a range of cells.

ParameterTypeDescription
borderEdgeNumberBorderType
borderStyleNumberCellBorderType
borderColorCellsColorBorder color.

setOutlineBorder(borderEdge, borderStyle, borderColor)

Sets outline border around a range of cells.

ParameterTypeDescription
borderEdgeNumberBorderType
borderStyleNumberCellBorderType
borderColorColorBorder color.

setOutlineBorders(borderStyle, borderColor)

Sets the outline borders around a range of cells with same border style and color.

ParameterTypeDescription
borderStyleNumberCellBorderType
borderColorCellsColorBorder color.

setOutlineBorders(borderStyle, borderColor)

Sets the outline borders around a range of cells with same border style and color.

ParameterTypeDescription
borderStyleNumberCellBorderType
borderColorColorBorder color.

setOutlineBorders(borderStyles, borderColors)

Sets out line borders around a range of cells. Both the length of borderStyles and borderStyles must be 4. The order of borderStyles and borderStyles must be top,bottom,left,right

ParameterTypeDescription
borderStylesArray of NumberBorder styles.
borderColorsArray ofColorBorder colors.

setRowHeight()

Sets or gets the height of rows in this range

setStyle(style, explicitFlag)

Apply the cell style.

ParameterTypeDescription
styleStyleThe cell style.
explicitFlagbooleanTrue, only overwriting formatting which is explicitly set.

setStyle(style)

Sets the style of the range.

ParameterTypeDescription
styleStyleThe Style object.

setValue()

Gets and sets the value of the range. If the range contains multiple cells, the returned/applied object should be Object[][].

toHtml(saveOptions)

Convert the range to html .

ParameterTypeDescription
saveOptionsHtmlSaveOptionsOptions for coverting range to html.

Returns: Array of byte — Array of byte

toImage(options)

Converts the range to image.

ParameterTypeDescription
optionsImageOrPrintOptionsThe options for converting this range to image

Returns: Array of byte — Array of byte

toJson(options)

Convert the range to JSON value.

ParameterTypeDescription
optionsJsonSaveOptionsThe options of converting

Returns: String — String

toString()

Returns a string represents the current Range object.

Returns: String — String

transpose()

Transpose (rotate) data from rows to columns or vice versa.

unMerge()

Unmerges merged cells of this range.

union(range)

Returns the union of two ranges. NOTE: This method is now obsolete. Instead, please use Range.UnionRanges() method. This method will be removed 12 months later since November 2023. Aspose apologizes for any inconvenience you may have experienced.

ParameterTypeDescription
rangeRangeThe range

Returns: ArrayList — ArrayList The union of two ranges.

unionRang(range)

Returns the union result of two ranges. NOTE: This method is now obsolete. Instead, please use Range.UnionRanges() method. This method will be removed 12 months later since May 2024. Aspose apologizes for any inconvenience you may have experienced.

ParameterTypeDescription
rangeRangeThe range

Returns: Array ofRange — Array ofRange The union of two ranges.

unionRanges(ranges)

Returns the union result of two ranges.

ParameterTypeDescription
rangesArray ofRangeThe range

Returns: UnionRange — UnionRange The union of two ranges.