Click or drag to resize

XlsRange Properties

The XlsRange type exposes the following members.

Properties
Name Description
Public property Code example BooleanValue
Returns or sets the bool value of the specified range.
Examples
The following code illustrates how to access Boolean property of the Range:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Set and get BooleanValue</para><para>worksheet.Range[2, 4].BooleanValue = true;</para><para>bool boolean = worksheet.Range[2, 4].BooleanValue;</para>
Public property Borders
Returns aBorders collection that represents the borders of a style or a range of cells (including a range defined as part of a conditional format).
Public property Code example BuiltInStyle
Gets/sets built in style.
Examples
The following code illustrates how to access BuiltInStyle property:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Set text</para><para>worksheet["C2"].Text = "Sample";</para><para>//Set built in style</para><para>worksheet["C2"].BuiltInStyle = BuiltInStyles.Accent3;</para><para>//Save to file</para><para>workbook.SaveToFile("BuiltInStyle.xlsx");</para>
Public property CellList
Returns a Range object that represents the cells in the specified range.
Public property Cells Obsolete.
Returns a Range object that represents the cells in the specified range.
Public property CellsCount
Gets number of cells.
Public property Code example CellStyleName
Gets/sets name of the style for the current range.
Examples
The following code illustrates how to access CellStyleName of the specified range:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Add and set style</para><para>CellStyle style = workbook.Styles.Add("CustomStyle");</para><para>worksheet["C2"].Style = style;</para><para>//Check Style name</para><para>Console.Write(worksheet["C2"].CellStyleName);</para>
Public property Code example Column
Returns the number of the first column in the first area in the specified range.
Examples
The following code illustrates how to access Column property of the Range:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Get specified column</para><para>int firstColumn = worksheet["E1:R3"].Column;</para>
Public property ColumnCount
Gets number of columns.
Public property ColumnGroupLevel
Column group level.
Public property Columns
For a Range object, it returns an array of Range objects that represent the columns in the specified range.
Public property Code example ColumnWidth
Returns or sets the width of all columns in the specified range.
Examples
The following code illustrates how to set the width of all columns in the specified range:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Set the ColumnWidth</para><para>worksheet["A1"].Text = "This cell contains sample text";</para><para>worksheet["A1"].ColumnWidth = 25;</para><para>//Save to file</para><para>workbook.SaveToFile("ColumnWidth.xlsx");</para>
Public property CombinedAddress
Returns the combined range reference in the language. Read-only String.
Public property CombinedCells
Gets the list of combined cells.
Public property Comment
Returns a Comment object that represents the comment associated with the cell in the upper-left corner of the range.
Public property ConditionalFormats Obsolete.
Collection of conditional formats for the range.
Public property Count
Returns the number of objects in the collection.
Public property CurrentRegion
Get the range associated with a range.
Public property Code example DataValidation
Get dataValidation of the sheet. Read Only.
Examples
The following code illustrates how to access DataValidation property of the Range:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Data validation for number</para><para>IDataValidation validation = worksheet.Range["A3"].DataValidation;</para><para>validation.AllowType = CellDataType.Integer;</para><para>//Value between 0 to 10</para><para>validation.CompareOperator = ValidationComparisonOperator.Between;</para><para>validation.Formula1 = "0";</para><para>validation.Formula2 = "10";</para><para>//Save to file</para><para>workbook.SaveToFile("DataValidation.xlsx");</para>
Public property Code example DateTimeValue
Gets/sets DateTime value of the range.
Examples
The following code illustrates how to set and access DateTimeValue property of the Range:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Set and get the DateTimeValue of specified range</para><para>worksheet.Range[2, 4].DateTimeValue = DateTime.Now;</para><para>DateTime dateTime = worksheet.Range[2, 4].DateTimeValue;</para><para>//Save to file</para><para>workbook.SaveToFile("DateTimeValue.xlsx");</para>
Public property DisplayedText
Gets cell displayed text.
Public property EndCell
Returns a Range object that represents the cell at the end of the region that contains the source range.
Public property EntireColumn
Returns a Range object that represents the entire column (or columns) that contains the specified range.
Public property EntireRow
Returns a Range object that represents the entire row (or rows) that contains the specified range. Read-only.
Public property Code example EnvalutedValue
Returns the calculated value of a formula.
Examples
The following code illustrates how to access a calculated value:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>workbook.LoadFromFile("Sample.xlsx");</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Returns the calculated value of a formula using the most current inputs</para><para>string calculatedValue = worksheet["C1"].EnvalutedValue;</para><para>Console.WriteLine(calculatedValue);</para>
Public property ErrorValue
Gets or sets error value of this range.
Public property ExtendedFormatIndex
Sets / gets index of extended format.
Protected property FirstColumn
Gets or sets the index of the first column in the range.
Protected property FirstRow
Gets or sets the first row of the range.
Public property Formula
Returns or sets the object's formula in A1-style notation and in the language of the macro.
Public property Code example FormulaArray
Returns or sets the array formula of a range.
Examples
The following code illustrates how to set and access FormulaArray property of the range:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Assign array formula</para><para>worksheet.Range["A1:D1"].FormulaArray = "{1,2,3,4}";</para><para>//Adding a named range for the range A1 to D1</para><para>worksheet.Names.Add("ArrayRange", worksheet.Range["A1:D1"]);</para><para>//Assign formula array with named range</para><para>worksheet.Range["A2:D2"].FormulaArray = "ArrayRange+100";</para><para>//Save to file</para><para>workbook.SaveToFile("FormulaArray.xlsx");</para>
Public property FormulaArrayR1C1
Returns or sets the formula for the object, using R1C1-style notation in the language of the macro
Public property FormulaBoolValue
Gets or sets bool value of the formula.
Public property FormulaDateTime
Gets or sets bool value of the formula.
Public property FormulaErrorValue
Gets or sets error value of the formula.
Public property FormulaNumberValue
Gets or sets double value of the formula.
Public property FormulaR1C1
Returns or sets the formula for the object, using R1C1-style notation in the language of the macro
Public property FormulaStringValue
Gets or sets string value of the range.
Public property FormulaValue
Gets formula value.
Public property Code example HasBoolean
Indicates whether range contains bool value.
Examples
The following code illustrates how to set and access HasBoolean property of the Range:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Assigning Value2 property of the Range</para><para>worksheet["A3"].Value2 = false;</para><para>//Checking Range types</para><para>bool isboolean = worksheet["A3"].HasBoolean;</para><para>//Save to file</para><para>workbook.SaveToFile("HasBoolean.xlsx");</para>
Public property HasComment
Gets a value indicating whether the cell has a comment.
Public property HasConditionFormats
Indicates whether each cell of the range has some conditional formatting.
Public property HasDataValidation
Indicates whether specified range object has data validation. If Range is not single cell, then returns true only if all cells have data validation. Read-only.
Public property Code example HasDateTime
Determines if all cells in the range contain datetime.
Examples
The following code illustrates how to set and access HasDateTime property of the Range:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Assigning Value2 property of the Range</para><para>worksheet["A1"].Value2 = DateTime.Now;</para><para>//Checking Range types</para><para>bool isDateTime =worksheet["A1"].HasDateTime;</para><para>//Save to file</para><para>workbook.SaveToFile("HasDateTime.xlsx");</para>
Public property HasError
Indicates whether range contains error value.
Public property HasExternalFormula
Check if the formula in the range has external links. Read-only.
Public property HasFormula
True if all cells in the range contain formulas;
Public property HasFormulaArray
Determines if all cells in the range contain array-entered formula.
Public property HasFormulaBoolValue
Determines if all cells in the range contain formula bool value..
Public property HasFormulaDateTime
Indicates if current range has formula value formatted as DateTime. Read-only.
Public property HasFormulaErrorValue
Determines if all cells in the range contain error value.
Public property HasFormulaNumberValue
Indicates whether current range has formula number value.
Public property HasFormulaStringValue
Indicates whether current range contains formula value which evaluated as string.
Public property Code example HasMerged
Indicates whether this range is part of merged range.
Examples
The following code illustrates how to access HasMerged property:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Set text</para><para>worksheet["A1"].Text = "Sample text in cell";</para><para>//Set merge</para><para>worksheet["A1:B1"].Merge();</para><para>//Check merge</para><para>Console.Write(worksheet["A1:B1"].HasMerged);</para>
Public property Code example HasNumber
Determines if any one cell in the range contain number.
Examples
The following code illustrates how to set and access Value2 property of the Range:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Assigning Value2 property of the Range</para><para>worksheet["A2"].Value2 = 45;</para><para>//Checking Range types</para><para>bool isNumber =worksheet["A2"].HasNumber;</para><para>//Save to file</para><para>workbook.SaveToFile("HasNumber.xlsx");</para>
Public property HasPictures
Indicates whether the range is blank.
Public property Code example HasRichText
Determines if all cells in the range contain rich text string.
Examples
The following code illustrates how to access HasRichText property:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Create style</para><para>IStyle style = workbook.Styles.Add("CustomStyle");</para><para>//Set rich text</para><para>IRichTextString richText = worksheet["C2"].RichText;</para><para>richText.Text = "Sample";</para><para>IFont font = style.Font;</para><para>font.Color = Color.Red;</para><para>richText.SetFont(0, 5, font);</para><para>//Check HasRichText</para><para>Console.Write(worksheet["C2"].HasRichText);</para><para>//Save to file</para><para>workbook.SaveToFile("HasRichText.xlsx");</para>
Public property HasString
Determines if all cells in the range contain string.
Public property Code example HasStyle
Determines if all cells in the range containdiffers from default style.
Examples
The following code illustrates how to access HasStyle property:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Add style</para><para>CellStyle style = workbook.Styles.Add("CustomStyle");</para><para>//Set color and style</para><para>style.Color = Color.Red;</para><para>worksheet["C2"].Style = style;</para><para>//Check HasStyle</para><para>Console.Write(worksheet["C2"].HasStyle);</para><para>//Save to file</para><para>workbook.SaveToFile("HasStyle.xlsx");</para>
Public property Code example HorizontalAlignment
Returns or sets the horizontal alignment for the specified object.
Examples
The following code illustrates how to set and access HasStyle property:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Set text</para><para>worksheet["A1"].Text = "Test";</para><para>//Set alignment</para><para>worksheet["A1"].HorizontalAlignment = HorizontalAlignType.Right;</para><para>//Save to file</para><para>workbook.SaveToFile("HorizontalAlignment.xlsx");</para>
Public property HtmlString
Gets and sets the html string which contains data and some formattings in this cell.
Public property Hyperlinks
Returns hyperlinks for this range.
Public property IgnoreErrorOptions
Represents ignore error options. If not single cell returs concatenateed flags.
Public property Code example IndentLevel
Returns or sets the indent level for the cell or range. value should be 0 between 15.
Examples
The following code illustrates how to set indent level for a cell:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Set text</para><para>worksheet["C2"].Text = "Sample";</para><para>//Set indent level</para><para>worksheet["C2"].IndentLevel = 2;</para><para>//Save to file</para><para>workbook.SaveToFile("IndentLevel.xlsx");</para>
Public property IsAllNumber
Determines if all cells in the range contain number.
Public property IsBlank
Indicates whether the range is blank.
Public property IsFormulaHidden
Determines if the formula will be hidden when the worksheet is protected.
Public property IsGroupedByColumn
Indicates whether this range is grouped by column.
Public property IsGroupedByRow
Indicates whether this range is grouped by row.
Public property IsInitialized
Indicates whether range has been initialized.
Protected property IsSingleCell
Checks if the current selection is a single cell.
Public property IsStringsPreserved
Indicates whether all values in the range are preserved as strings.
Public property Code example IsWrapText
Determines if Microsoft Excel wraps the text in the object.
Examples
The following code illustrates how to access WrapText property:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Set text</para><para>worksheet["A1"].Text = "This cell contains sample text";</para><para>//Set wrap text</para><para>worksheet["A1"].IsWrapText = true;</para><para>//Save to file</para><para>workbook.SaveToFile("IsWrapText.xlsx");</para>
Public property Item String
Gets cell range. Read-only.
Public property Item Int32, Int32
Gets / sets cell by row and column index. Row and column indexes are one-based.
Public property Item String, Boolean
Gets cell range. Read-only.
Public property Item Int32, Int32, Int32, Int32
Get cell range. Row and column indexes are one-based. Read-only.
Public property LastColumn
Gets or sets last column of the range.
Public property LastRow
Gets or sets last row of the range.
Public property MergeArea
Returns a Range object that represents the merged range containing the specified cell.
Public property Code example NumberFormat
Returns or sets the format code for the object.
Examples
The following code illustrates how to set NumberFormat property:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Set data</para><para>worksheet["C2"].Value = "3100.23";</para><para>//Set number format</para><para>worksheet["C2"].NumberFormat = "#,##1.##";</para><para>//Save to file</para><para>workbook.SaveToFile("NumberFormat.xlsx");</para>
Public property Code example NumberText
Returns cell text for number format.
Examples
The following code illustrates how to access NumberText property of the Range:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Gets cell value with its number format</para><para>CellRange range= worksheet.Range[3, 1];</para><para>range.Value = "1/1/2015";</para><para>range.NumberFormat = "dd-MMM-yyyy";</para><para>string numberText = range.NumberText;</para><para>//Save to file</para><para>workbook.SaveToFile("NumberText.xlsx");</para>
Public property NumberValue
Gets or sets number value of the range.
Public property Parent
Parent object for this object.
Public property Code example RangeAddress
Returns the range reference in the language of the macro. Read-only String.
Examples
The following code illustrates how to access Address property of the Range:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Get RangeAddress</para><para>string address = worksheet.Range[3, 4].RangeAddress;</para>
Public property Code example RangeAddressLocal
Returns the range reference for the specified range in the language of the user.
Examples
The following code illustrates how to access AddressLocal property of the Range:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Get RangeAddressLocal</para><para>string address = worksheet.Range[3, 4].RangeAddressLocal;</para>
Public property Code example RangeGlobalAddress
Returns the range reference in the language of the macro.
Examples
The following code illustrates how to access AddressGlobal property of the Range:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Get RangeAddress</para><para>string address = worksheet.Range[3, 4].RangeGlobalAddress;</para>
Public property RangeGlobalAddress2007
Gets address global in the format required by Excel 2007.
Public property RangeGlobalAddressWithoutSheetName
Return global address without worksheet name.
Public property Code example RangeR1C1Address
Returns the range reference using R1C1 notation.
Examples
The following code illustrates how to access AddressR1C1 property of the Range:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Get RangeR1C1Address</para><para>string address = worksheet.Range[3, 4].RangeR1C1Address;</para>
Public property Code example RangeR1C1AddressLocal
Returns the range reference using R1C1 notation.
Examples
The following code illustrates how to access AddressR1C1Local property of the Range:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Get RangeR1C1AddressLocal</para><para>string address = worksheet.Range[3, 4].RangeR1C1Address;</para>
Protected property ReferenceCount
Get quantity of instance references.
(Inherited from XlsObject .)
Public property RichText
Returns a RichTextString object that represents the rich text style.
Public property Row
Returns the number of the first row of the first area in the range.
Public property RowCount
Gets number of rows.
Public property RowGroupLevel
Row group level.
Public property Code example RowHeight
Returns the height of all the rows in the range specified, measured in points.
Examples
The following code illustrates how to set row height:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Set text</para><para>worksheet["A1"].Text = "Test";</para><para>//Set row height</para><para>worksheet["A1"].RowHeight = 30;</para><para>//Save to file</para><para>workbook.SaveToFile("RowHeight.xlsx");</para>
Public property Rows
For a Range object, it returns an array of Range objects that represent the rows in the specified range.
Public property Style
Returns a Style object that represents the style of the specified range.
Public property Text
Gets / sets text of range.
Public property TimeSpanValue
Gets or sets timespan value of cell.
Public property Code example Value
Returns or sets the value of the specified range.
Examples
The following code illustrates how to set Value of the specified range:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Set value of the range</para><para>CellRange range= worksheet.Range[3, 1];</para><para>range.Value = "1/1/2015";</para><para>//Save to file</para><para>workbook.SaveToFile("Value.xlsx");</para>
Public property Code example Value2
Returns or sets the cell value. It's not use for current and datetime types.
Examples
The following code illustrates how to access Value2 property of the Range:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Assigning Value2 property of the Range</para><para>worksheet["A1"].Value2 = DateTime.Now;</para><para>worksheet["A3"].Value2 = false;</para><para>//Checking Range types</para><para>Console.WriteLine(worksheet["A1"].HasDateTime);</para><para>Console.WriteLine(worksheet["A3"].HasBoolean);</para>
Public property Code example VerticalAlignment
Returns or sets the vertical alignment of the specified object.
Examples
The following code illustrates how to set vertical alignment type:
<para>//Create worksheet</para><para>Workbook workbook = new Workbook();</para><para>Worksheet worksheet = workbook.Worksheets[0];</para><para>//Set text</para><para>worksheet["A1"].Text = "Test";</para><para>//Set alignment</para><para>worksheet["A1"].VerticalAlignment = VerticalAlignType.Top;</para><para>//Save to file</para><para>workbook.SaveToFile("VerticalAlignment.xlsx");</para>
Protected property Workbook
Gets the workbook .
Public property Worksheet
Returns a worksheet object that represents the worksheet containing the specified range.
Public property WorksheetName
Returns name of the parent worksheet.
Top
See Also