Range

Range class

Encapsulates the object that represents a range of cells within a spreadsheet.

Properties

NameTypeDescription
CurrentRegionRangeReturns a Range object that represents the current region. The current region is a range bounded by any combination of b
HyperlinksHyperlink[]Gets all hyperlink in the range.
RowCountintGets the count of rows in the range.
ColumnCountintGets the count of columns in the range.
NameStringGets or sets the name of the range. Named range is supported. For example, range.Name = “Sheet1!MyRange”;
RefersToStringGets the range’s refers to.
AddressStringGets address of the range.
LeftfloatGets the distance, in points, from the left edge of column A to the left edge of the range.
TopfloatGets the distance, in points, from the top edge of row 1 to the top edge of the range.
WidthfloatGets the width of a range in points.
HeightfloatGets the width of a range in points.
FirstRowintGets the index of the first row of the range.
FirstColumnintGets the index of the first column of the range.
ValueObjectGets and sets the value of the range. If the range contains multiple cells, the returned/applied object should be Object
ColumnWidthfloatSets or gets the column width of this range
RowHeightfloatSets or gets the height of rows in this range
EntireColumnRangeGets a Range object that represents the entire column (or columns) that contains the specified range.
EntireRowRangeGets a Range object that represents the entire row (or rows) that contains the specified range.
WorksheetWorksheetGets the Worksheet object which contains this range.
Item (int, int)CellGets Cell object in this range.

Methods

NameDescription
autoFillAutomaticall fill the target range.
addHyperlinkAdds a hyperlink to a specified cell or a range of cells.
iteratorGets the enumerator for cells in this Range.

When traversing elements by the returned Enumerator, the cells collection | | isIntersect | Indicates whether the range is intersect.

If the two ranges area not in the same worksheet ,return false. | | intersect | Returns a Range object that represents the rectangular intersection of two ranges.

If the two ranges are not intersecte | | unionRang | Returns the union result of two ranges.

NOTE: This method is now obsolete. Instead, please use Range.UnionRanges() meth | | unionRanges | Returns the union result of two ranges. | | union | Returns the union of two ranges.

NOTE: This method is now obsolete. Instead, please use Range.UnionRanges() method. Thi | | isBlank | Indicates whether the range contains values. | | merge | Combines a range of cells into a single cell.

Reference the merged cell via the address of the upper-left cell in the r | | unMerge | Unmerges merged cells of this range. | | putValue | Puts a value into the range, if appropriate the value will be converted to other data type and cell’s number format will | | setStyle | Apply the cell style. | | applyStyle | Applies formats for a whole range.

Each cell in this range will contains a Style object. So this is a memory-consuming | | setOutlineBorders | Sets the outline borders around a range of cells with same border style and color. | | setOutlineBorder | Sets outline border around a range of cells. | | setInsideBorders | Set inside borders of the range. | | moveTo | Move the current range to the dest range. | | copyData | Copies cell data (including formulas) from a source range. | | copyValue | Copies cell value from a source range. | | copyStyle | Copies style settings from a source range. | | copy | Copying the range with paste special options. | | transpose | Transpose (rotate) data from rows to columns or vice versa. | | getCellOrNull | Gets Cell object or null in this range. | | getOffset | Gets Range range by offset. | | toString | Returns a string represents the current Range object. | | toImage | Converts the range to image. | | toJson | Convert the range to JSON value. | | toHtml | Convert the range to html . | | clear | | | clearContents | | | clearFormats | | | clearComments | | | clearHyperlinks | |

Range.CurrentRegion property

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.

Type: Range

Gets all hyperlink in the range.

Type: Hyperlink[]

Range.RowCount property

Gets the count of rows in the range.

Type: int

Range.ColumnCount property

Gets the count of columns in the range.

Type: int

Range.Name property

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

Type: String

Range.RefersTo property

Gets the range’s refers to.

Type: String

Range.Address property

Gets address of the range.

Type: String

Range.Left property

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

Type: float

Range.Top property

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

Type: float

Range.Width property

Gets the width of a range in points.

Type: float

Range.Height property

Gets the width of a range in points.

Type: float

Range.FirstRow property

Gets the index of the first row of the range.

Type: int

Range.FirstColumn property

Gets the index of the first column of the range.

Type: int

Range.Value property

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

Type: Object

Range.ColumnWidth property

Sets or gets the column width of this range

Type: float

Range.RowHeight property

Sets or gets the height of rows in this range

Type: float

Range.EntireColumn property

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

Type: Range

Range.EntireRow property

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

Type: Range

Range.Worksheet property

Gets the Worksheet object which contains this range.

Type: Worksheet

Range.Item (int, int) property

Gets Cell object in this range.

Type: Cell

autoFill(target) (1 of 2)

Automaticall fill the target range.

ParameterTypeDescription
targetRangethe target range.

autoFill(target, autoFillType) (2 of 2)

Automaticall fill the target range.

ParameterTypeDescription
targetRangeThe targed range.
autoFillTypeintA AutoFillType value. The auto fill type.

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 object.

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).

Returns: The cells enumerator

isIntersect(range)

Indicates whether the range is intersect.

If the two ranges area not in the same worksheet ,return false.

ParameterTypeDescription
rangeRangeThe range.

Returns: Whether the range is intersect.

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: Returns a Range object

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: The union of two ranges.

unionRanges(ranges)

Returns the union result of two ranges.

ParameterTypeDescription
rangesRange[]The range

Returns: The union of two ranges.

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: The union of two ranges.

isBlank()

Indicates whether the range contains values.

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.

unMerge()

Unmerges merged cells of this 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

setStyle(style, explicitFlag) (1 of 2)

Apply the cell style.

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

setStyle(style) (2 of 2)

Sets the style of the range.

ParameterTypeDescription
styleStyleThe Style 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.

setOutlineBorders(borderStyle, borderColor) (1 of 3)

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

ParameterTypeDescription
borderStyleintA CellBorderType value. Border style.
borderColorCellsColorBorder color.

setOutlineBorders(borderStyle, borderColor) (2 of 3)

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

ParameterTypeDescription
borderStyleintA CellBorderType value. Border style.
borderColorColorBorder color.

setOutlineBorders(borderStyles, borderColors) (3 of 3)

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
borderStylesNumber ArrayBorder styles.
borderColorsColor[]Border colors.

setOutlineBorder(borderEdge, borderStyle, borderColor) (1 of 2)

Sets outline border around a range of cells.

ParameterTypeDescription
borderEdgeintA BorderType value. Border edge.
borderStyleintA CellBorderType value. Border style.
borderColorCellsColorBorder color.

setOutlineBorder(borderEdge, borderStyle, borderColor) (2 of 2)

Sets outline border around a range of cells.

ParameterTypeDescription
borderEdgeintA BorderType value. Border edge.
borderStyleintA CellBorderType value. Border style.
borderColorColorBorder color.

setInsideBorders(borderEdge, lineStyle, borderColor)

Set inside borders of the range.

ParameterTypeDescription
borderEdgeintA BorderType value. Inside borde type, only can be BorderType.VERTICAL and BorderType.HORIZONTAL .
lineStyleintA CellBorderType value. The border style.
borderColorCellsColorThe color of the border.

moveTo(destRow, destColumn)

Move the current range to the dest range.

ParameterTypeDescription
destRowintThe start row of the dest range.
destColumnintThe start column of the dest range.

copyData(range)

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

ParameterTypeDescription
rangeRangeSource Range object.

copyValue(range)

Copies cell value from a source range.

ParameterTypeDescription
rangeRangeSource Range object.

copyStyle(range)

Copies style settings from a source range.

ParameterTypeDescription
rangeRangeSource Range object.

copy(range, options) (1 of 2)

Copying the range with paste special options.

ParameterTypeDescription
rangeRangeThe source range.
optionsPasteOptionsThe paste special options.

copy(range) (2 of 2)

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

ParameterTypeDescription
rangeRangeSource Range object.

transpose()

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

getCellOrNull(rowOffset, columnOffset)

Gets Cell object or null in this range.

ParameterTypeDescription
rowOffsetintRow offset in this range, zero based.
columnOffsetintColumn offset in this range, zero based.

Returns: Cell object.

getOffset(rowOffset, columnOffset)

Gets Range range by offset.

ParameterTypeDescription
rowOffsetintRow offset in this range, zero based.
columnOffsetintColumn offset in this range, zero based.

toString()

Returns a string represents the current Range object.

toImage(options)

Converts the range to image.

ParameterTypeDescription
optionsImageOrPrintOptionsThe options for converting this range to image

toJson(options)

Convert the range to JSON value.

ParameterTypeDescription
optionsJsonSaveOptionsThe options of converting

toHtml(saveOptions)

Convert the range to html .

ParameterTypeDescription
saveOptionsHtmlSaveOptionsOptions for coverting range to html.

clear()

clearContents()

clearFormats()

clearComments()