CellRange Class
Cell range is a rectangular group of worksheet cells.
- Inheritance:
- System.
Object CellRange
Remarks
Cell range is determined by its First
Value property set will set value of multiple cells or of a merged range. Value property get has meaning only if range is merged; otherwise, exception is thrown.
Properties
Comment
Gets or sets merged cell comment.
Property Value
Overrides
Remarks
Exceptions
- System.
Invalid Operation Exception
Cell range has defined comment only if it's merged.
See Also
EndPosition
Gets name of the last (bottom-right) cell in this cell range.
Property Value
- System.
String
FirstColumnIndex
Gets index of the first (leftmost) column.
Property Value
- System.
Int32
FirstRowIndex
Gets index of the first (topmost) row.
Property Value
- System.
Int32
Formula
Gets or sets formula string.
Property Value
- System.
String
Overrides
Remarks
In XLSX files, reading and writing of all formulas are supported.
In XLS files, reading and writing of all common and most of the advanced formulas are supported.
In XLSB files, reading and writing of all common and most of the advanced formulas are supported.
In ODS files, reading and writing of all formulas are supported, however, OpenOffice formulas don't have the same syntax as Excel formulas.
In CSV files, reading of all formulas is supported.
For more information on formulas, consult Microsoft Excel documentation.
Exceptions
- System.
Invalid Operation Exception
Property get is attempted on a cell range which is not merged.
FormulaR1C1
Gets or sets a formula string in R1C1 notation.
Property Value
- System.
String
Overrides
Height
Gets height of this cell range, in rows.
Property Value
- System.
Int32
Hyperlink
Gets or sets merged cell hyperlink.
Property Value
Overrides
Remarks
Exceptions
- System.
Invalid Operation Exception
Cell range has defined hyperlink only if it's merged.
See Also
IndexingMode
Gets indexing mode used for cell range.
Property Value
Remarks
If Height is 1, indexing mode is Horizontal.
Otherwise, if Width is 1, indexing mode is Vertical.
Otherwise, indexing mode is Rectangular.
IsAnyCellMerged
Returns true is any cell in this cell range is merged; otherwise, false.
Property Value
- System.
Boolean
Item[Int32]
Gets excel cell at the specified index.
Parameters
contextIndex
- System.
Int32
The zero-based context index of the cell.
Property Value
Remarks
If Indexing
If Indexing
If Indexing
See Also
Item[Int32, Int32]
Gets excel cell at the specified relative position.
Parameters
relativeRow
- System.
Int32
The zero-based relative row position.
relativeColumn
- System.
Int32
The zero-based relative column position.
Property Value
Remarks
Absolute position of excel cell is calculated by adding relativeRow
and relativeColumn
to First
Item[String]
Gets excel cell with the specified full or partial name.
Parameters
contextName
- System.
String
Full or partial name of the cell.
Property Value
Remarks
If Indexing
If Indexing
If Indexing
See Also
LastColumnIndex
Gets index of the last (rightmost) column.
Property Value
- System.
Int32
LastRowIndex
Gets index of the last (bottommost) row.
Property Value
- System.
Int32
Merged
Gets or sets whether cells in this range are merged.
Property Value
- System.
Boolean
Remarks
By setting this property to true, you are merging all the cells (Excel
When modifying merged cell, whole merged range is modified. For example, if you set Value, value of merged range will be modified. You can find out if the cell is merged by checking if Merged
Exceptions
- System.
Argument Exception
Merged range can't be created because some of the cells in the range are already merged.
StartPosition
Gets name of the first (top-left) cell in this cell range.
Property Value
- System.
String
Value
Gets or sets cell value on one or more excel cells.
Property Value
- System.
Object
Overrides
Remarks
Property set will set value of multiple cells or of a merged range.
Property get has meaning only if range is Merged; otherwise, exception is thrown.
Exceptions
- System.
Invalid Operation Exception
Property get is attempted on a cell range which is not merged.
See Also
Width
Gets width of this cell range, in columns.
Property Value
- System.
Int32
Methods
AutoFitColumnWidth()
Changes the range's column widths to fit the contents.
Use this method instead of multiple calls to Auto
AutoFitRowHeight(Boolean)
Changes the range's row heights to fit the contents.
Use this method instead of multiple calls to Auto
Parameters
autoFitMergedRanges
- System.
Boolean
true if merged ranges should be taken into account; otherwise, false.
Calculate()
Calculates formula for every excel cell in this range.
Overrides
CopyTo(ExcelWorksheet, Int32, Int32)
Copies this cell range to another worksheet.
[ComVisible(false)]
public void CopyTo(ExcelWorksheet destinationWorksheet, int absoluteRow, int absoluteColumn)
Parameters
destinationWorksheet
- Excel
Worksheet
Destination worksheet.
absoluteRow
- System.
Int32
Absolute index of the destination row.
absoluteColumn
- System.
Int32
Absolute index of the destination column.
Remarks
Destination cell range has the same width and height as this cell range.
System.
- breaks Excel worksheet row or column limit,
- overlaps with source range, or
- overlaps with existing merged range.
Exceptions
- System.
Argument Out Of Range Exception
Destination range is invalid.
- System.
Argument Null Exception
Destination worksheet is null.
CopyTo(ExcelWorksheet, Int32, Int32, CopyOptions)
Copies this cell range to another worksheet with specified copy options.
[ComVisible(false)]
public void CopyTo(ExcelWorksheet destinationWorksheet, int absoluteRow, int absoluteColumn, CopyOptions copyOptions)
Parameters
destinationWorksheet
- Excel
Worksheet
Destination worksheet.
absoluteRow
- System.
Int32
Absolute index of the destination row.
absoluteColumn
- System.
Int32
Absolute index of the destination column.
copyOptions
- Copy
Options
The copy options.
Remarks
Destination cell range has the same width and height as this cell range.
System.
- breaks Excel worksheet row or column limit,
- overlaps with source range, or
- overlaps with existing merged range.
Exceptions
- System.
Argument Out Of Range Exception
Destination range is invalid.
- System.
Argument Null Exception
Destination worksheet is null.
CopyTo(ExcelWorksheet, String)
Copies this cell range to another worksheet.
[ComVisible(false)]
public void CopyTo(ExcelWorksheet destinationWorksheet, string topLeftCell)
Parameters
destinationWorksheet
- Excel
Worksheet
Destination worksheet.
topLeftCell
- System.
String
Full name of the top-left cell of the destination range.
Remarks
Destination cell range has the same width and height as this cell range.
System.
- breaks Excel worksheet row or column limit,
- overlaps with source range, or
- overlaps with existing merged range.
Exceptions
- System.
Argument Out Of Range Exception
Destination range is invalid.
- System.
Argument Null Exception
Destination worksheet is null.
- System.
Argument Exception
Top-left cell is incorrectly specified.
CopyTo(ExcelWorksheet, String, CopyOptions)
Copies this cell range to another worksheet with specified copy options.
[ComVisible(false)]
public void CopyTo(ExcelWorksheet destinationWorksheet, string topLeftCell, CopyOptions copyOptions)
Parameters
destinationWorksheet
- Excel
Worksheet
Destination worksheet.
topLeftCell
- System.
String
Full name of the top-left cell of the destination range.
copyOptions
- Copy
Options
The copy options.
Remarks
Destination cell range has the same width and height as this cell range.
System.
- breaks Excel worksheet row or column limit,
- overlaps with source range, or
- overlaps with existing merged range.
Exceptions
- System.
Argument Out Of Range Exception
Destination range is invalid.
- System.
Argument Null Exception
Destination worksheet is null.
- System.
Argument Exception
Top-left cell is incorrectly specified.
CopyTo(Int32, Int32)
Copies this cell range to another position in the same worksheet.
Parameters
absoluteRow
- System.
Int32
Absolute index of the destination row.
absoluteColumn
- System.
Int32
Absolute index of the destination column.
Remarks
Destination cell range has the same width and height as this cell range.
System.
- breaks Excel worksheet row or column limit,
- overlaps with source range, or
- overlaps with existing merged range.
Exceptions
- System.
Argument Out Of Range Exception
Destination range is invalid.
- System.
Argument Null Exception
Destination worksheet is null.
CopyTo(Int32, Int32, CopyOptions)
Copies this cell range to another position in the same worksheet with specified copy options.
[ComVisible(false)]
public void CopyTo(int absoluteRow, int absoluteColumn, CopyOptions copyOptions)
Parameters
absoluteRow
- System.
Int32
Absolute index of the destination row.
absoluteColumn
- System.
Int32
Absolute index of the destination column.
copyOptions
- Copy
Options
The copy options.
Remarks
Destination cell range has the same width and height as this cell range.
System.
- breaks Excel worksheet row or column limit,
- overlaps with source range, or
- overlaps with existing merged range.
Exceptions
- System.
Argument Out Of Range Exception
Destination range is invalid.
- System.
Argument Null Exception
Destination worksheet is null.
CopyTo(String)
Copies this cell range to another position in the same worksheet or in another worksheet.
Parameters
topLeftCell
- System.
String
Full name of the top-left cell of the destination range (e.g. "D4", "Sheet2!D5", etc.).
Remarks
Destination cell range has the same width and height as this cell range.
System.
- breaks Excel worksheet row or column limit,
- overlaps with source range, or
- overlaps with existing merged range.
Exceptions
- System.
Argument Out Of Range Exception
Destination range is invalid.
- System.
Argument Null Exception
Destination worksheet is null.
- System.
Argument Exception
Top-left cell is incorrectly specified.
CopyTo(String, CopyOptions)
Copies this cell range to another position in the same worksheet or in another worksheet with specified copy options.
Parameters
topLeftCell
- System.
String
Full name of the top-left cell of the destination range (e.g. "D4", "Sheet2!D5", etc.).
copyOptions
- Copy
Options
The copy options.
Remarks
Destination cell range has the same width and height as this cell range.
System.
- breaks Excel worksheet row or column limit,
- overlaps with source range, or
- overlaps with existing merged range.
Exceptions
- System.
Argument Out Of Range Exception
Destination range is invalid.
- System.
Argument Null Exception
Destination worksheet is null.
- System.
Argument Exception
Top-left cell is incorrectly specified.
Equals(Object)
Determines whether the specified System.
Parameters
obj
- System.
Object
The System.
Returns
- System.
Boolean
Overrides
Filter()
Gets the Auto
Auto
Returns
The Auto
Remarks
This method has the same affect as Filter(Boolean) with parameter set to true.
The filter is set as active filter on a table if this range is inside any table in this worksheet. Otherwise the filter is set as active filter on the parent worksheet
Filter(Boolean)
Gets the Autoactive
is true; otherwise, a new Autoactive
is true.
Auto
Parameters
active
- System.
Boolean
if set to true, gets or sets the Auto
Returns
The Autoactive
is true; otherwise, a new Autoactive
is true.
Remarks
Use this method (with parameter active
set to false) to create multiple independent Auto
If the parameter active
is set to true the filter is set as active filter on a table if this range is inside any table in this worksheet. Otherwise the filter is set as active filter on the parent worksheet
FindAllText(String)
Finds all occurrences which match the specified System.
Parameters
text
- System.
String
Text to search.
Returns
Exceptions
- System.
Argument Null Exception
text
is null.
FindAllText(String, Boolean)
Finds all occurrences which match the specified System.
Parameters
text
- System.
String
Text to search.
matchCase
- System.
Boolean
true to match exact case, false otherwise.
Returns
Exceptions
- System.
Argument Null Exception
text
is null.
FindAllText(String, Boolean, Boolean)
Finds all occurrences which match the specified System.
public IEnumerable<ExcelCell> FindAllText(string text, bool matchCase, bool matchEntireCellContents)
Parameters
text
- System.
String
Text to search.
matchCase
- System.
Boolean
true to match exact case, false otherwise.
matchEntireCellContents
- System.
Boolean
true to match entire cell contents, false otherwise.
Returns
Exceptions
- System.
Argument Null Exception
text
is null.
FindAllText(Regex)
Finds all occurrences which match the specified System.
Parameters
regex
- System.
Text. Regular Expressions. Regex
The System.
Returns
Exceptions
- System.
Argument Null Exception
regex
is null.
FindText(String, out ExcelCell)
Finds the first occurrence of the specified text in the current cell range.
Parameters
text
- System.
String
Text to search.
Returns
- System.
Boolean
true if text is found, false otherwise.
Exceptions
- System.
Argument Null Exception
text
is null.
FindText(String, Boolean, out ExcelCell)
Finds the first occurrence of the specified text in the current cell range.
Parameters
text
- System.
String
Text to search.
matchCase
- System.
Boolean
true to match exact case, false otherwise.
Returns
- System.
Boolean
true if text is found, false otherwise.
Exceptions
- System.
Argument Null Exception
text
is null.
FindText(String, Boolean, Boolean, out ExcelCell)
Finds the first occurrence of the specified text in the current cell range.
public bool FindText(string text, bool matchCase, bool matchEntireCellContents, out ExcelCell cell)
Parameters
text
- System.
String
Text to search.
matchCase
- System.
Boolean
true to match exact case, false otherwise.
matchEntireCellContents
- System.
Boolean
true to match entire cell contents, false otherwise.
Returns
- System.
Boolean
true if text is found, false otherwise.
Exceptions
- System.
Argument Null Exception
text
is null.
FindText(String, Boolean, Boolean, out Int32, out Int32)
Finds the first occurrence of the specified text in the current cell range.
public bool FindText(string text, bool matchCase, bool matchEntireCellContents, out int row, out int column)
Parameters
text
- System.
String
Text to search.
matchCase
- System.
Boolean
true to match exact case, false otherwise.
matchEntireCellContents
- System.
Boolean
true to match entire cell contents, false otherwise.
row
- System.
Int32
Index of the row where the text was found or -1 if no text was found.
column
- System.
Int32
Index of the column where the text was found or -1 if no text was found.
Returns
- System.
Boolean
true if text is found, false otherwise.
Exceptions
- System.
Argument Null Exception
text
is null.
FindText(String, Boolean, out Int32, out Int32)
Finds the first occurrence of the specified text in the current cell range.
Parameters
text
- System.
String
Text to search.
matchCase
- System.
Boolean
true to match exact case, false otherwise.
row
- System.
Int32
Index of the row where the text was found or -1 if no text was found.
column
- System.
Int32
Index of the column where the text was found or -1 if no text was found.
Returns
- System.
Boolean
true if text is found, false otherwise.
Exceptions
- System.
Argument Null Exception
text
is null.
FindText(String, out Int32, out Int32)
Finds the first occurrence of the specified text in the current cell range.
Parameters
text
- System.
String
Text to search.
row
- System.
Int32
Index of the row where the text was found or -1 if no text was found.
column
- System.
Int32
Index of the column where the text was found or -1 if no text was found.
Returns
- System.
Boolean
true if text is found, false otherwise.
Exceptions
- System.
Argument Null Exception
text
is null.
FindText(Regex, out ExcelCell)
Finds the first occurrence which matches the specified System.
Parameters
regex
- System.
Text. Regular Expressions. Regex
The System.
Returns
- System.
Boolean
true if text is found, false otherwise.
Exceptions
- System.
Argument Null Exception
regex
is null.
FindText(Regex, out Int32, out Int32)
Finds the first occurrence which matches the specified System.
Parameters
regex
- System.
Text. Regular Expressions. Regex
The System.
row
- System.
Int32
Index of the row where the text was found or -1 if no text was found.
column
- System.
Int32
Index of the column where the text was found or -1 if no text was found.
Returns
- System.
Boolean
true if text is found, false otherwise.
Exceptions
- System.
Argument Null Exception
regex
is null.
GetCurrentRegion()
Selects a worksheet region to which the cell range belongs to.
Returns
The worksheet region to which the cell range belongs to.
GetEnumerator()
Returns an enumerator for the Cell
Returns
Remarks
Returns default enumerator that iterates all cells in the range. If you are only reading existing cells (values or formatting), use more appropriate Get
GetHashCode()
Returns a hash code for this Cell
Returns
- System.
Int32
An integer value that specifies a hash value for this Cell
Overrides
GetReadEnumerator()
Returns enumerator for the Cell
Returns
An enumerator for the Cell
Remarks
Returns enumerator that iterates only already allocated cells in the range. If you are only reading existing cells (values or formatting), use this enumerator as it is faster and doesn't allocate unnecessary cells.
GetSubrange(String)
Returns new cell range using A1 style notation.
Parameters
reference
- System.
String
The cell range reference in A1 style notation.
Returns
New cell range using A1 style notation.
Remarks
New cell range must be within this cell range. Multiple area selection is not supported (e.g. "A1:B2,C3:D4,E5:F6").
See Also
GetSubrange(String, String)
Returns new cell range using start and end position.
Parameters
firstCell
- System.
String
Name of first (top-left) cell.
lastCell
- System.
String
Name of last (bottom-right) cell.
Returns
New cell range using start and end position.
Remarks
New cell range must be within this cell range.
Exceptions
- System.
Argument Out Of Range Exception
Arguments are out of range.
See Also
GetSubrangeAbsolute(Int32, Int32, Int32, Int32)
Returns new cell range using absolute indexing.
public CellRange GetSubrangeAbsolute(int firstAbsoluteRow, int firstAbsoluteColumn, int lastAbsoluteRow, int lastAbsoluteColumn)
Parameters
firstAbsoluteRow
- System.
Int32
Absolute index of the first row.
firstAbsoluteColumn
- System.
Int32
Absolute index of the first column.
lastAbsoluteRow
- System.
Int32
Absolute index of the last row.
lastAbsoluteColumn
- System.
Int32
Absolute index of the last column.
Returns
New cell range using absolute indexing.
Remarks
New cell range must be within this cell range.
Exceptions
- System.
Argument Out Of Range Exception
Arguments are out of range.
See Also
GetSubrangeRelative(Int32, Int32, Int32, Int32)
Returns new cell range using relative indexing.
public CellRange GetSubrangeRelative(int relativeRow, int relativeColumn, int width, int height)
Parameters
relativeRow
- System.
Int32
Relative index of the first row.
relativeColumn
- System.
Int32
Relative index of the first column.
width
- System.
Int32
Width of new cell range in columns.
height
- System.
Int32
Height of new cell range in rows.
Returns
New cell range using relative indexing.
Remarks
New cell range must be within this cell range.
Exceptions
- System.
Argument Out Of Range Exception
Arguments are out of range.
See Also
Insert(InsertShiftDirection)
Inserts a range by shifting cells in the specified direction.
Parameters
direction
- Insert
Shift Direction
The shift direction.
Overrides
Overlaps(CellRange)
Checks if this cell range overlaps with another cell range.
Parameters
range
- Cell
Range
Cell range.
Returns
- System.
Boolean
true if cell ranges overlap; otherwise, false.
Exceptions
- System.
Argument Null Exception
range
is null.
PositionToRowColumn(String, out Int32, out Int32)
Converts position string ("A1", "BN27", etc.) to row and column index.
Parameters
position
- System.
String
Position string.
row
- System.
Int32
Row index.
column
- System.
Int32
Column index.
Remove(RemoveShiftDirection)
Removes a range by shifting cells in the specified direction.
Parameters
direction
- Remove
Shift Direction
The shift direction.
Overrides
RowColumnToPosition(Int32, Int32)
Converts row and column index to position string ("A1", "BN27", etc.).
Parameters
row
- System.
Int32
Row index.
column
- System.
Int32
Column index.
Returns
- System.
String
Position string.
SetArrayFormula(String)
Sets array formula (also known as CSE formula) to the range of cells.
Parameters
formula
- System.
String
The array formula.
See Also
Sort(Boolean)
Gets the Sortactive
is true; otherwise, a new Sortactive
is true.
Sort
Parameters
active
- System.
Boolean
Returns
Remarks
Use this method (with parameter active
set to false) to create multiple independent Sort
Subtotal(Int32, ConsolidationFunction, Int32[])
Creates subtotals for the current cell range.
Parameters
groupBy
- System.
Int32
The column index based on which grouping should be done.
function
- Consolidation
Function
The subtotal function to be applied.
totalList
- System.
Int32 []
An array of column indexes to which the subtotals are added.
Subtotal(Int32, ConsolidationFunction, Int32[], Boolean)
Creates subtotals for the current cell range.
public void Subtotal(int groupBy, ConsolidationFunction function, int[] totalList, bool replace)
Parameters
groupBy
- System.
Int32
The column index based on which grouping should be done.
function
- Consolidation
Function
The subtotal function to be applied.
totalList
- System.
Int32 []
An array of column indexes to which the subtotals are added.
replace
- System.
Boolean
true to replace existing subtotals, false otherwise.
Subtotal(Int32, ConsolidationFunction, Int32[], Boolean, Boolean)
Creates subtotals for the current cell range.
public void Subtotal(int groupBy, ConsolidationFunction function, int[] totalList, bool replace, bool pageBreaks)
Parameters
groupBy
- System.
Int32
The column index based on which grouping should be done.
function
- Consolidation
Function
The subtotal function to be applied.
totalList
- System.
Int32 []
An array of column indexes to which the subtotals are added.
replace
- System.
Boolean
true to replace existing subtotals, false otherwise.
pageBreaks
- System.
Boolean
true to add page breaks after each group, false otherwise.
Subtotal(Int32, ConsolidationFunction, Int32[], Boolean, Boolean, Boolean)
Creates subtotals for the current cell range.
public void Subtotal(int groupBy, ConsolidationFunction function, int[] totalList, bool replace, bool pageBreaks, bool summaryBelowData)
Parameters
groupBy
- System.
Int32
The column index based on which grouping should be done.
function
- Consolidation
Function
The subtotal function to be applied.
totalList
- System.
Int32 []
An array of column indexes to which the subtotals are added.
replace
- System.
Boolean
true to replace existing subtotals, false otherwise.
pageBreaks
- System.
Boolean
true to add page breaks after each group, false otherwise.
summaryBelowData
- System.
Boolean
true to place the summary below data, false otherwise.
Operators
Equality(CellRange, CellRange)
Determines whether first
and second
Cell
Parameters
Returns
- System.
Boolean
true if first
and second
Cell
Inequality(CellRange, CellRange)
Determines whether first
and second
Cell
Parameters
Returns
- System.
Boolean
true if first
and second
Cell
Inherited Properties
Character | Returns all Formatted (Inherited from Abstract |
Name | Gets the name of Abstract (Inherited from Abstract |
Style | Gets or sets the cell formatting of one or more cells. (Inherited from Abstract |
Inherited Methods
Clear(Clear | Clears the range (content, formatting, comment, hyperlink or all). (Inherited from Abstract |
Get | Returns a Formatted (Inherited from Abstract |
Get | Returns a Formatted (Inherited from Abstract |
Replace | Replaces all matches of the specified System. (Inherited from Abstract |
Replace | Replaces all occurrences of the specified text with another text in the current Abstract (Inherited from Abstract |
Replace | Replaces all occurrences of the specified text with another text in the current Abstract (Inherited from Abstract |
Replace | Replaces all occurrences of the specified text with another text in the current Abstract (Inherited from Abstract |
To | Returns a System. (Inherited from Abstract |