Class Range

Range class

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

public class Range

Properties

NameDescription
Address { get; }Gets address of the range.
ColumnCount { get; }Gets the count of columns in the range.
ColumnWidth { get; set; }Sets or gets the column width of this range
CurrentRegion { get; }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.
EntireColumn { get; }Gets a Range object that represents the entire column (or columns) that contains the specified range.
EntireRow { get; }Gets a Range object that represents the entire row (or rows) that contains the specified range.
FirstColumn { get; }Gets the index of the first column of the range.
FirstRow { get; }Gets the index of the first row of the range.
Height { get; }Gets the width of a range in points.
Hyperlinks { get; }Gets all hyperlink in the range.
Item { get; }Gets Cell object in this range.
Left { get; }Gets the distance, in points, from the left edge of column A to the left edge of the range.
Name { get; set; }Gets or sets the name of the range.
RefersTo { get; }Gets the range’s refers to.
RowCount { get; }Gets the count of rows in the range.
RowHeight { get; set; }Sets or gets the height of rows in this range
Top { get; }Gets the distance, in points, from the top edge of row 1 to the top edge of the range.
Value { get; set; }Gets and sets the value of the range.
Width { get; }Gets the width of a range in points.
Worksheet { get; }Gets the Worksheetobject which contains this range.

Methods

NameDescription
AddHyperlink(string, string, string)Adds a hyperlink to a specified cell or a range of cells.
ApplyStyle(Style, StyleFlag)Applies formats for a whole range.
AutoFill(Range)Automaticall fill the target range.
AutoFill(Range, AutoFillType)Automaticall fill the target range.
Copy(Range)Copies data (including formulas), formatting, drawing objects etc. from a source range.
Copy(Range, PasteOptions)Copying the range with paste special options.
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.
ExportDataTable()Exports data in this range to a DataTable object.
ExportDataTable(ExportTableOptions)Exports data in this range to a DataTable object.
ExportDataTableAsString()Exports data in this range to a DataTable object.
GetCellOrNull(int, int)Gets Cell object or null in this range.
GetEnumerator()Gets the enumerator for cells in this Range.
GetOffset(int, int)Gets Range range by offset.
Intersect(Range)Returns a Range object that represents the rectangular intersection of two ranges.
IsBlank()Indicates whether the range contains values.
IsIntersect(Range)Indicates whether the range is intersect.
Merge()Combines a range of cells into a single cell.
MoveTo(int, int)Move the current range to the dest range.
PutValue(string, bool, bool)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.
SetInsideBorders(BorderType, CellBorderType, CellsColor)Set inside borders of the range.
SetOutlineBorder(BorderType, CellBorderType, CellsColor)Sets outline border around a range of cells.
SetOutlineBorder(BorderType, CellBorderType, Color)Sets outline border around a range of cells.
SetOutlineBorders(CellBorderType, CellsColor)Sets the outline borders around a range of cells with same border style and color.
SetOutlineBorders(CellBorderType, Color)Sets the outline borders around a range of cells with same border style and color.
SetOutlineBorders(CellBorderType[], Color[])Sets out line borders around a range of cells.
SetStyle(Style)Sets the style of the range.
SetStyle(Style, bool)Apply the cell style.
override ToString()Returns a string represents the current Range object.
Union(Range)(Obsolete.) Returns the union of two ranges.
UnionRang(Range)Returns the union result of two ranges.
UnMerge()Unmerges merged cells of this range.

Remarks

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.

Examples

The following example shows how to create a range and set value the range of Excel.

[C#]

//Instantiating a Workbook object
Workbook workbook = new Workbook();
// Get the first Worksheet Cells.
Cells cells = workbook.Worksheets[0].Cells;
// Create a range (A1:D3).
Range range = cells.CreateRange("A1", "D3");
// Set value to the range.
range.Value = "Hello";
//Save the Excel file
workbook.Save("book1.xlsm");

 [Visual Basic]

'Instantiating a Workbook object
Dim workbook As Workbook = New Workbook()
'Get the first Worksheet Cells.
Dim cells as Cells = workbook.Worksheets[0].Cells
'Create a range (A1:D3).
Dim range as Range = cells.CreateRange("A1", "D3")
'Set value to the range.
range.Value = "Hello"
'Save the Excel file
workbook.Save("book1.xlsm")

See Also