Class XlsRange
- Namespace
- Spire.Xls.Core.Spreadsheet
- Assembly
- Spire.XLS.dll
public class XlsRange : XlsObject, ICombinedRange, IXLSRange, IExcelApplication, IEnumerable<IXLSRange>, IEnumerable, IDisposable
- Inheritance
-
XlsRange
- Implements
- Derived
- Inherited Members
Fields
DEF_MAX_HEIGHT
public const double DEF_MAX_HEIGHT = 409.5
Field Value
m_book
protected XlsWorkbook m_book
Field Value
m_iBottomRow
protected int m_iBottomRow
Field Value
m_iLeftColumn
protected int m_iLeftColumn
Field Value
m_iRightColumn
protected int m_iRightColumn
Field Value
m_iTopRow
protected int m_iTopRow
Field Value
m_style
protected CellBaseStyle m_style
Field Value
Properties
BooleanValue
Returns or sets the bool value of the specified range.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Set and get BooleanValue
worksheet.Range[2, 4].BooleanValue = true;
bool boolean = worksheet.Range[2, 4].BooleanValue;
public bool BooleanValue { get; set; }
Property Value
Borders
Returns a Borders collection that represents the borders of a style
or a range of cells (including a range defined as part of a
conditional format).
//Create worksheetWorkbook workbook = new Workbook();Worksheet worksheet = workbook.Worksheets[0];//Set textworksheet["C2"].Text = "Sample";//Set bordersIBorders borders = worksheet["C2"].Borders;//Set line styleborders[BordersLineType.EdgeTop].LineStyle = LineStyleType.Thin;borders[BordersLineType.EdgeBottom].LineStyle = LineStyleType.Thin;//Set border colorborders[BordersLineType.EdgeTop].Color = Color.Red;borders[BordersLineType.EdgeBottom].Color = Color.Red;//Save to fileworkbook.SaveToFile("CellFormats.xlsx");
public IBorders Borders { get; }
Property Value
BuiltInStyle
Gets/sets built in style.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Set text
worksheet["C2"].Text = "Sample";
//Set built in style
worksheet["C2"].BuiltInStyle = BuiltInStyles.Accent3;
//Save to file
workbook.SaveToFile("BuiltInStyle.xlsx");
public BuiltInStyles? BuiltInStyle { get; set; }
Property Value
CellList
Returns a Range object that represents the cells in the specified range.
Read-only.
//Create worksheetWorkbook workbook = new Workbook();Worksheet worksheet = workbook.Worksheets[0];//Set text. The content contained by ![CDATA[]] will be expressed as plain textListCellRange cells = worksheet["A1:E8"].CellList;//Do some manipulationsforeach (CellRange Range in cells) Range.Text = Range.RangeAddressLocal;//Save to fileworkbook.SaveToFile("CellList.xlsx");
public List<CellRange> CellList { get; }
Property Value
CellStyleName
Gets/sets name of the style for the current range.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Add and set style
CellStyle style = workbook.Styles.Add("CustomStyle");
worksheet["C2"].Style = style;
//Check Style name
Console.Write(worksheet["C2"].CellStyleName);
public string CellStyleName { get; set; }
Property Value
Cells
Returns a Range object that represents the cells in the specified range. Read-only.
[Obsolete("Please use CellList")]
public CellRange[] Cells { get; }
Property Value
CellsCount
Gets number of cells.
public int CellsCount { get; }
Property Value
Column
Returns the number of the first column in the first area in the specified range.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Get specified column
int firstColumn = worksheet["E1:R3"].Column;
public int Column { get; }
Property Value
ColumnCount
Gets number of columns.
public int ColumnCount { get; }
Property Value
ColumnGroupLevel
Column group level.
public int ColumnGroupLevel { get; }
Property Value
Remarks
-1 - column group is not same. 0 - Not group 1 - 7 - group level.
ColumnWidth
Returns or sets the width of all columns in the specified range.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Set the ColumnWidth
worksheet["A1"].Text = "This cell contains sample text";
worksheet["A1"].ColumnWidth = 25;
//Save to file
workbook.SaveToFile("ColumnWidth.xlsx");
public double ColumnWidth { get; set; }
Property Value
Columns
For a Range object, returns an array of Range objects that represent the
columns in the specified range.
//Create worksheetWorkbook workbook = new Workbook();Worksheet worksheet = workbook.Worksheets[0];//Set columnsIXLSRange[] columns = worksheet["A1:E8"].Columns;//Do some manipulationsforeach (IXLSRange column in columns) column.Text = column.RangeAddressLocal;//Save to fileworkbook.SaveToFile("Columns.xlsx");
public IXLSRange[] Columns { get; }
Property Value
CombinedAddress
Returns the combined range reference in the language. Read-only String.
public string CombinedAddress { get; }
Property Value
CombinedCells
public List<CellRange> CombinedCells { get; }
Property Value
Comment
Returns a Comment object that represents the comment associated with the cell in the upper-left corner of the range.
public ICommentShape Comment { get; }
Property Value
ConditionalFormats
Collection of conditional formats.
[Obsolete("This Property is Obsolete;use XlsWorksheet.ConditionalFormats instead")]
public ConditionalFormats ConditionalFormats { get; }
Property Value
Count
Returns the number of objects in the collection.
public int Count { get; }
Property Value
CurrentRegion
Get the range associated with a range.
public IXLSRange CurrentRegion { get; }
Property Value
DataValidation
Get dataValidation of the sheet. Read Only.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Data validation for number
IDataValidation validation = worksheet.Range["A3"].DataValidation;
validation.AllowType = CellDataType.Integer;
//Value between 0 to 10
validation.CompareOperator = ValidationComparisonOperator.Between;
validation.Formula1 = "0";
validation.Formula2 = "10";
//Save to file
workbook.SaveToFile("DataValidation.xlsx");
public Validation DataValidation { get; }
Property Value
DateTimeValue
Gets/sets DateTime value of the range.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Set and get the DateTimeValue of specified range
worksheet.Range[2, 4].DateTimeValue = DateTime.Now;
DateTime dateTime = worksheet.Range[2, 4].DateTimeValue;
//Save to file
workbook.SaveToFile("DateTimeValue.xlsx");
public DateTime DateTimeValue { get; set; }
Property Value
DisplayedText
Gets cell displayed text.
public string DisplayedText { get; }
Property Value
EndCell
Returns a Range object that represents the cell at the end of the region that contains the source range.
public IXLSRange EndCell { get; }
Property Value
EntireColumn
Returns a Range object that represents the entire column (or columns) that contains the specified range. Read-only.
public IXLSRange EntireColumn { get; }
Property Value
EntireRow
Returns a Range object that represents the entire row (or rows) that contains the specified range. Read-only.
public IXLSRange EntireRow { get; }
Property Value
EnvalutedValue
Returns the calculated value of a formula.
//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
//Returns the calculated value of a formula using the most current inputs
string calculatedValue = worksheet["C1"].EnvalutedValue;
Console.WriteLine(calculatedValue);
public string EnvalutedValue { get; }
Property Value
ErrorValue
Gets or sets error value of this range.
public string ErrorValue { get; set; }
Property Value
ExtendedFormatIndex
[CLSCompliant(false)]
public ushort ExtendedFormatIndex { get; set; }
Property Value
FirstColumn
protected int FirstColumn { get; set; }
Property Value
FirstRow
protected int FirstRow { get; set; }
Property Value
Formula
Returns or sets the object's formula in A1-style notation and in the language of the macro.
public string Formula { get; set; }
Property Value
FormulaArray
Returns or sets the array formula of a range.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Assign array formula
worksheet.Range["A1:D1"].FormulaArray = "{1,2,3,4}";
//Adding a named range for the range A1 to D1
worksheet.Names.Add("ArrayRange", worksheet.Range["A1:D1"]);
//Assign formula array with named range
worksheet.Range["A2:D2"].FormulaArray = "ArrayRange+100";
//Save to file
workbook.SaveToFile("FormulaArray.xlsx");
public string FormulaArray { get; set; }
Property Value
FormulaArrayR1C1
Returns or sets the formula for the object, using R1C1-style notation in the language of the macro
public string FormulaArrayR1C1 { get; set; }
Property Value
FormulaBoolValue
Returns the calculated value of the formula as a boolean.
public bool FormulaBoolValue { get; set; }
Property Value
FormulaDateTime
Gets or sets bool value of the formula.
public DateTime FormulaDateTime { get; set; }
Property Value
FormulaErrorValue
Gets or sets error value of the formula.
public string FormulaErrorValue { get; set; }
Property Value
FormulaNumberValue
Gets or sets double value of the formula.
public double FormulaNumberValue { get; set; }
Property Value
FormulaR1C1
Returns or sets the formula for the object, using R1C1-style notation in the language of the macro
public string FormulaR1C1 { get; set; }
Property Value
FormulaStringValue
Gets or sets string value of the range.
public string FormulaStringValue { get; set; }
Property Value
FormulaValue
Gets formula value.
public object FormulaValue { get; }
Property Value
HasBoolean
Indicates whether range contains bool value.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Assigning Value2 property of the Range
worksheet["A3"].Value2 = false;
//Checking Range types
bool isboolean = worksheet["A3"].HasBoolean;
//Save to file
workbook.SaveToFile("HasBoolean.xlsx");
public bool HasBoolean { get; }
Property Value
HasComment
public bool HasComment { get; }
Property Value
HasConditionFormats
Indicates whether each cell of the range has some conditional formatting.
public bool HasConditionFormats { get; }
Property Value
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 bool HasDataValidation { get; }
Property Value
HasDateTime
Determines if all cells in the range contain datetime.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Assigning Value2 property of the Range
worksheet["A1"].Value2 = DateTime.Now;
//Checking Range types
bool isDateTime = worksheet["A1"].HasDateTime;
//Save to file
workbook.SaveToFile("HasDateTime.xlsx");
public bool HasDateTime { get; }
Property Value
HasError
Indicates whether range contains error value.
public bool HasError { get; }
Property Value
HasExternalFormula
Check if the formula in the range has external links. Read-only.
public bool HasExternalFormula { get; }
Property Value
HasFormula
True if all cells in the range contain formulas;
public bool HasFormula { get; }
Property Value
HasFormulaArray
Determines if all cells in the range contain array-entered formula.
public bool HasFormulaArray { get; }
Property Value
HasFormulaBoolValue
Determines if all cells in the range contain formula bool value..
public bool HasFormulaBoolValue { get; }
Property Value
HasFormulaDateTime
Indicates if current range has formula value formatted as DateTime. Read-only.
public bool HasFormulaDateTime { get; }
Property Value
HasFormulaErrorValue
Determines if all cells in the range contain error value.
public bool HasFormulaErrorValue { get; }
Property Value
HasFormulaNumberValue
Indicates whether current range has formula number value.
public bool HasFormulaNumberValue { get; }
Property Value
HasFormulaStringValue
Indicates if the current range has formula string value. Read-only.
public bool HasFormulaStringValue { get; }
Property Value
HasMerged
Indicates whether this range is part of merged range.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Set text
worksheet["A1"].Text = "Sample text in cell";
//Set merge
worksheet["A1:B1"].Merge();
//Check merge
Console.Write(worksheet["A1:B1"].HasMerged);
public bool HasMerged { get; }
Property Value
HasNumber
Determines if any one cell in the range contain number.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Assigning Value2 property of the Range
worksheet["A2"].Value2 = 45;
//Checking Range types
bool isNumber = worksheet["A2"].HasNumber;
//Save to file
workbook.SaveToFile("HasNumber.xlsx");
public bool HasNumber { get; }
Property Value
HasPictures
Indicates whether the range is blank.
public bool HasPictures { get; }
Property Value
HasRichText
Determines if all cells in the range contain rich text string.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Create style
IStyle style = workbook.Styles.Add("CustomStyle");
//Set rich text
IRichTextString richText = worksheet["C2"].RichText;
richText.Text = "Sample";
IFont font = style.Font;
font.Color = Color.Red;
richText.SetFont(0, 5, font);
//Check HasRichText
Console.Write(worksheet["C2"].HasRichText);
//Save to file
workbook.SaveToFile("HasRichText.xlsx");
public bool HasRichText { get; }
Property Value
HasString
Determines if all cells in the range contain string.
public bool HasString { get; }
Property Value
HasStyle
Determines if all cells in the range contain differs from default style.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Add style
CellStyle style = workbook.Styles.Add("CustomStyle");
//Set color and style
style.Color = Color.Red;
worksheet["C2"].Style = style;
//Check HasStyle
Console.Write(worksheet["C2"].HasStyle);
//Save to file
workbook.SaveToFile("HasStyle.xlsx");
public bool HasStyle { get; }
Property Value
HorizontalAlignment
Returns or sets the horizontal alignment for the specified object.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Set text
worksheet["A1"].Text = "Test";
//Set alignment
worksheet["A1"].HorizontalAlignment = HorizontalAlignType.Right;
//Save to file
workbook.SaveToFile("HorizontalAlignment.xlsx");
public HorizontalAlignType HorizontalAlignment { get; set; }
Property Value
HtmlString
Gets and sets the html string which contains data and some formattings in this cell.
public string HtmlString { get; set; }
Property Value
Hyperlinks
Returns hyperlinks for this range.
public IHyperLinks Hyperlinks { get; }
Property Value
IgnoreErrorOptions
Represents ignore error options. If not single cell returs concatenateed flags.
public IgnoreErrorType IgnoreErrorOptions { get; set; }
Property Value
IndentLevel
Returns or sets the indent level for the cell or range. value should be 0 between 15.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Set text
worksheet["C2"].Text = "Sample";
//Set indent level
worksheet["C2"].IndentLevel = 2;
//Save to file
workbook.SaveToFile("IndentLevel.xlsx");
public int IndentLevel { get; set; }
Property Value
IsAllNumber
Determines if all cells in the range contain number.
public bool IsAllNumber { get; }
Property Value
IsBlank
Indicates whether the range is blank.
public bool IsBlank { get; }
Property Value
IsFormulaHidden
Determines if the formula will be hidden when the worksheet is protected.
public bool IsFormulaHidden { get; set; }
Property Value
IsGroupedByColumn
Indicates whether this range is grouped by column.
public bool IsGroupedByColumn { get; }
Property Value
IsGroupedByRow
Indicates whether this range is grouped by row.
public bool IsGroupedByRow { get; }
Property Value
IsInitialized
Indicates whether range has been initialized.
public bool IsInitialized { get; }
Property Value
IsSingleCell
protected bool IsSingleCell { get; }
Property Value
IsStringsPreserved
Indicates whether all values in the range are preserved as strings.
public bool? IsStringsPreserved { get; set; }
Property Value
- bool?
IsWrapText
Determines if Microsoft Excel wraps the text in the object.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Set text
worksheet["A1"].Text = "This cell contains sample text";
//Set wrap text
worksheet["A1"].IsWrapText = true;
//Save to file
workbook.SaveToFile("IsWrapText.xlsx");
public bool IsWrapText { get; set; }
Property Value
this[int, int]
Gets / sets cell by row and column index. Row and column indexes are one-based.
public IXLSRange this[int row, int column] { get; set; }
Parameters
Property Value
this[int, int, int, int]
Get cell range. Row and column indexes are one-based. Read-only.
public IXLSRange this[int row, int column, int lastRow, int lastColumn] { get; }
Parameters
Property Value
this[string]
Get cell range. Read-only.
public IXLSRange this[string name] { get; }
Parameters
name
string
Property Value
this[string, bool]
Gets cell range. Read-only.
public IXLSRange this[string name, bool IsR1C1Notation] { get; }
Parameters
Property Value
LastColumn
Gets or sets last column of the range.
public int LastColumn { get; set; }
Property Value
LastRow
Gets or sets last row of the range.
public int LastRow { get; set; }
Property Value
MergeArea
Returns a Range object that represents the merged range containing
the specified cell. If the specified cell is not in a merged range,
this property returns NULL. Read-only.
//Create worksheetWorkbook workbook = new Workbook();Worksheet worksheet = workbook.Worksheets[0];//Set textworksheet["C2"].Text = "Sample text in cell";//Set mergeworksheet["C2:D3"].Merge();//Check merge areaConsole.Write(worksheet["C2"].MergeArea.AddressLocal);
public IXLSRange MergeArea { get; }
Property Value
NumberFormat
Returns or sets the format code for the object.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Set data
worksheet["C2"].Value = "3100.23";
//Set number format
worksheet["C2"].NumberFormat = "#,##1.##";
//Save to file
workbook.SaveToFile("NumberFormat.xlsx");
public string NumberFormat { get; set; }
Property Value
NumberText
Returns cell text for number format.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Gets cell value with its number format
CellRange range= worksheet.Range[3, 1];
range.Value = "1/1/2015";
range.NumberFormat = "dd-MMM-yyyy";
string numberText = range.NumberText;
//Save to file
workbook.SaveToFile("NumberText.xlsx");
public string NumberText { get; }
Property Value
NumberValue
Gets or sets number value of the range.
public double NumberValue { get; set; }
Property Value
Parent
public object Parent { get; }
Property Value
RangeAddress
Returns the range reference in the language of the macro.
Read-only String.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Get RangeAddress
string address = worksheet.Range[3, 4].RangeAddress;
public string RangeAddress { get; }
Property Value
RangeAddressLocal
Returns the range reference for the specified range in the language of the user.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Get RangeAddressLocal
string address = worksheet.Range[3, 4].RangeAddressLocal;
public string RangeAddressLocal { get; }
Property Value
RangeGlobalAddress
Returns the range reference in the language of the macro.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Get RangeAddress
string address = worksheet.Range[3, 4].RangeGlobalAddress;
public string RangeGlobalAddress { get; }
Property Value
RangeGlobalAddress2007
Gets address global in the format required by Excel 2007.
public string RangeGlobalAddress2007 { get; }
Property Value
RangeGlobalAddressWithoutSheetName
Return global address without worksheet name.
public string RangeGlobalAddressWithoutSheetName { get; }
Property Value
RangeR1C1Address
Returns the range reference using R1C1 notation.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Get RangeR1C1Address
string address = worksheet.Range[3, 4].RangeR1C1Address;
public string RangeR1C1Address { get; }
Property Value
RangeR1C1AddressLocal
Returns the range reference using R1C1 notation.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Get RangeR1C1AddressLocal
string address = worksheet.Range[3, 4].RangeR1C1Address;
public string RangeR1C1AddressLocal { get; }
Property Value
RichText
String with rich text formatting. Read-only.
//Create worksheetWorkbook workbook = new Workbook();Worksheet worksheet = workbook.Worksheets[0];//Create styleIStyle style = workbook.Styles.Add("CustomStyle");//Set rich textIRichTextString richText = worksheet["C2"].RichText;richText.Text = "Sample text";//Set rich text fontIFont font = style.Font;font.IsBold = true;richText.SetFont(0, 5, font);//Save to fileworkbook.SaveToFile("RichText.xlsx");
public IRichTextString RichText { get; }
Property Value
Row
Returns the number of the first row of the first area in the range.
public int Row { get; }
Property Value
RowCount
Gets number of rows.
public int RowCount { get; }
Property Value
RowGroupLevel
Row group level.
public int RowGroupLevel { get; }
Property Value
Remarks
-1 - column group is not same. 0 - Not group 1 - 7 - group level.
RowHeight
Returns the height of all the rows in the range specified, measured in points.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Set text
worksheet["A1"].Text = "Test";
//Set row height
worksheet["A1"].RowHeight = 30;
//Save to file
workbook.SaveToFile("RowHeight.xlsx");
public double RowHeight { get; set; }
Property Value
Rows
For a Range object, returns an array of Range objects that represent the
rows in the specified range.
//Create worksheetWorkbook workbook = new Workbook();Worksheet worksheet = workbook.Worksheets[0];//Set rowsIXLSRange[] rows = worksheet["A1:E8"].Rows;//Do some manipulationsforeach (IXLSRange row in rows) row.Text = row.RangeAddressLocal;//Save to fileworkbook.SaveToFile("Rows.xlsx");
public IXLSRange[] Rows { get; }
Property Value
Style
Returns a Style object that represents the style of the specified
range. Read/write IStyle.
//Create worksheetWorkbook workbook = new Workbook();Worksheet worksheet = workbook.Worksheets[0];//Set textworksheet["C2"].Text = "Sample";//Add and set styleCellStyle style = workbook.Styles.Add("BorderStyle");style.Color = Color.Red;worksheet["C2"].Style = style;//Save to fileworkbook.SaveToFile("Style.xlsx");
public IStyle Style { get; set; }
Property Value
Text
Gets / sets text of range.
public string Text { get; set; }
Property Value
TimeSpanValue
Gets or sets timespan value of cell.
public TimeSpan TimeSpanValue { get; set; }
Property Value
Value
Returns or sets the value of the specified range.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Set value of the range
CellRange range= worksheet.Range[3, 1];
range.Value = "1/1/2015";
//Save to file
workbook.SaveToFile("Value.xlsx");
public string Value { get; set; }
Property Value
Value2
Returns or sets the cell value.
It's not use for current and datetime types.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Assigning Value2 property of the Range
worksheet["A1"].Value2 = DateTime.Now;
worksheet["A3"].Value2 = false;
//Checking Range types
Console.WriteLine(worksheet["A1"].HasDateTime);
Console.WriteLine(worksheet["A3"].HasBoolean);
public object Value2 { get; set; }
Property Value
VerticalAlignment
Returns or sets the vertical alignment of the specified object.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Set text
worksheet["A1"].Text = "Test";
//Set alignment
worksheet["A1"].VerticalAlignment = VerticalAlignType.Top;
//Save to file
workbook.SaveToFile("VerticalAlignment.xlsx");
public VerticalAlignType VerticalAlignment { get; set; }
Property Value
Workbook
protected XlsWorkbook Workbook { get; }
Property Value
Worksheet
Returns a worksheet object that represents the worksheet containing the specified range.
public IWorksheet Worksheet { get; }
Property Value
WorksheetName
Returns name of the parent worksheet.
public string WorksheetName { get; }
Property Value
Methods
Activate()
Active single cell in the worksheet
public IXLSRange Activate()
Returns
- IXLSRange
Returns the active cell.
Activate(bool)
Activates a single cell, scroll to it and activates the corresponding sheet.
To select a range of cells, use the Select method.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Activates 'F1' cell.
worksheet.Range["F1"].Activate(true);
//Save to file
workbook.SaveToFile("Activate.xlsx");
public virtual IXLSRange Activate(bool scroll)
Parameters
scroll
boolTrue to scroll to the cell
Returns
- IXLSRange
Returns the active cell.
AddCombinedRange(CellRange)
public CellRange AddCombinedRange(CellRange cr)
Parameters
cr
CellRange
Returns
AddComment()
Adds a comment to the range.
public ICommentShape AddComment()
Returns
- ICommentShape
Created comment or exists one.
AddComment(ICommentShape)
protected void AddComment(ICommentShape comment)
Parameters
comment
ICommentShape
AddComment(bool)
public ICommentShape AddComment(bool bIsParseOptions)
Parameters
bIsParseOptions
bool
Returns
ApplyStyle(IStyle, CellStyleFlag)
public void ApplyStyle(IStyle style, CellStyleFlag flag)
Parameters
style
IStyleflag
CellStyleFlag
AutoFitColumns()
Changes the width of the columns in the range in the range to achieve the best fit.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Auto-fit columns
worksheet.Range["B4"].Text = "Fit the content to column";
worksheet.Range["B4"].AutoFitColumns();
//Save to file
workbook.SaveToFile("AutoFitRows.xlsx");
public void AutoFitColumns()
AutoFitRows()
Changes the width of the height of the rows in the range to achieve the best fit.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Auto-fit rows
worksheet.Range["A2"].Text = "Fit the content to row";
worksheet.Range["A2"].IsWrapText = true;
worksheet.Range["A2"].AutoFitRows();
//Save to file
workbook.SaveToFile("AutoFitRows.xlsx");
public void AutoFitRows()
BorderAround()
Sets around border for current range.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Set text
worksheet["C2"].Text = "Sample";
worksheet["D2"].Text = "text";
worksheet["C3"].Text = "in";
worksheet["D3"].Text = "cell";
//Set border
worksheet["C2:D3"].BorderAround();
//Save to file
workbook.SaveToFile("BorderAround.xlsx");
public void BorderAround()
BorderAround(LineStyleType)
Sets around border for current range.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Set text
worksheet["C2"].Text = "Sample";
worksheet["D2"].Text = "text";
worksheet["C3"].Text = "in";
worksheet["D3"].Text = "cell";
//Set border
worksheet["C2:D3"].BorderAround(LineStyleType.Thick);
//Save to file
workbook.SaveToFile("BorderAround.xlsx");
public void BorderAround(LineStyleType borderLine)
Parameters
borderLine
LineStyleTypeRepresents border line.
BorderAround(LineStyleType, ExcelColors)
Sets around border for current range.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Set text
worksheet["C2"].Text = "Sample";
worksheet["D2"].Text = "text";
worksheet["C3"].Text = "in";
worksheet["D3"].Text = "cell";
//Set border
worksheet["C2:D3"].BorderAround(LineStyleType.Thick , ExcelColors.Red);
//Save to file
workbook.SaveToFile("BorderAround.xlsx");
public void BorderAround(LineStyleType borderLine, ExcelColors borderColor)
Parameters
borderLine
LineStyleTypeRepresents border line.
borderColor
ExcelColorsRepresents border color as ExcelColors.
BorderAround(LineStyleType, Color)
Sets around border for current range.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Set text
worksheet["C2"].Text = "Sample";
worksheet["D2"].Text = "text";
worksheet["C3"].Text = "in";
worksheet["D3"].Text = "cell";
//Set border
worksheet["C2:D3"].BorderAround(LineStyleType.Thick , Color.Red);
//Save to file
workbook.SaveToFile("BorderAround.xlsx");
public void BorderAround(LineStyleType borderLine, Color borderColor)
Parameters
borderLine
LineStyleTypeRepresents border line.
borderColor
ColorRepresents border color.
BorderInside()
Sets inside border for current range.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Set text
worksheet["C2"].Text = "Sample";
worksheet["D2"].Text = "text";
worksheet["C3"].Text = "in";
worksheet["D3"].Text = "cell";
//Set border
worksheet["C2:D3"].BorderInside();
//Save to file
workbook.SaveToFile("BorderInside.xlsx");
public void BorderInside()
BorderInside(LineStyleType)
Sets inside border for current range.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Set text
worksheet["C2"].Text = "Sample";
worksheet["D2"].Text = "text";
worksheet["C3"].Text = "in";
worksheet["D3"].Text = "cell";
//Set border
worksheet["C2:D3"].BorderInside(LineStyleType.Thick);
//Save to file
workbook.SaveToFile("BorderInside.xlsx");
public void BorderInside(LineStyleType borderLine)
Parameters
borderLine
LineStyleTypeRepresents border line.
BorderInside(LineStyleType, ExcelColors)
Sets inside border for current range.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Set text
worksheet["C2"].Text = "Sample";
worksheet["D2"].Text = "text";
worksheet["C3"].Text = "in";
worksheet["D3"].Text = "cell";
//Set border
worksheet["C2:D3"].BorderInside(LineStyleType.Thick , ExcelColors.Red);
//Save to file
workbook.SaveToFile("BorderInside.xlsx");
public void BorderInside(LineStyleType borderLine, ExcelColors borderColor)
Parameters
borderLine
LineStyleTypeRepresents border line.
borderColor
ExcelColorsRepresents border color as ExcelColors.
BorderInside(LineStyleType, Color)
Sets inside border for current range.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Set text
worksheet["C2"].Text = "Sample";
worksheet["D2"].Text = "text";
worksheet["C3"].Text = "in";
worksheet["D3"].Text = "cell";
//Set border
worksheet["C2:D3"].BorderInside(LineStyleType.Thick , Color.Red);
//Save to file
workbook.SaveToFile("BorderInside.xlsx");
public void BorderInside(LineStyleType borderLine, Color borderColor)
Parameters
borderLine
LineStyleTypeRepresents border line.
borderColor
ColorRepresents border color.
BorderNone()
Sets none border for current range.
//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
//Remove borders
worksheet["C2"].BorderNone();
//Save to file
workbook.SaveToFile("BorderNone.xlsx");
public void BorderNone()
CalculateAllValue()
Caculate all formula for the specified range
public void CalculateAllValue()
CheckRange(int, int)
protected void CheckRange(int row, int column)
Parameters
Clear(ExcelClearOptions)
Clears the cell based on clear options.
//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
//Clears the Range C2 with its clear options
worksheet.Range["C2"].Clear(ExcelClearOptions.ClearAll);
//Save to file
workbook.SaveToFile("ClearContents.xlsx");
public void Clear(ExcelClearOptions option)
Parameters
option
ExcelClearOptionsRepresents the clear options.
Clear(bool)
protected void Clear(bool isClearFormat)
Parameters
isClearFormat
bool
ClearAll()
Clears the entire object.
public void ClearAll()
ClearConditionalFormats()
Clears conditional formats.
public void ClearConditionalFormats()
ClearContents()
Clear the contents of the Range.
//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
//Clears the Range C2
worksheet.Range["C2"].ClearContents();
//Save to file
workbook.SaveToFile("ClearContents.xlsx");
public void ClearContents()
Clone(object, Dictionary<string, string>, XlsWorkbook)
public IXLSRange Clone(object parent, Dictionary<string, string> rangeNames, XlsWorkbook book)
Parameters
parent
objectrangeNames
Dictionary<string, string>book
XlsWorkbook
Returns
CollapseGroup(GroupByType)
Collapses current group.
//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
//Collapse group
worksheet.Range["A5:A15"].CollapseGroup(GroupByType.ByRows);
//Save to file
workbook.SaveToFile("CollapseGroup.xlsx");
public void CollapseGroup(GroupByType groupBy)
Parameters
groupBy
GroupByTypeThis parameter specifies whether the grouping should be performed by rows or by columns.
ConvertToNumber()
Convert number that stored as text to number
public void ConvertToNumber()
CopyToClipboard()
[Obsolete("the method is not implemented")]
public void CopyToClipboard()
Dispose()
public void Dispose()
ExpandGroup(GroupByType)
Expands current group.
//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
//Expand group with flag set to expand parent
worksheet.Range["A5:A15"].ExpandGroup(GroupByType.ByRows);
//Save to file
workbook.SaveToFile("ExpandGroup.xlsx");
public void ExpandGroup(GroupByType groupBy)
Parameters
groupBy
GroupByTypeThis parameter specifies whether the grouping should be performed by rows or by columns.
ExpandGroup(GroupByType, ExpandCollapseFlags)
Expands current group.
//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
//Expand group with flag set to expand parent
worksheet.Range["A5:A15"].ExpandGroup(GroupByType.ByRows, ExpandCollapseFlags.ExpandParent);
//Save to file
workbook.SaveToFile("ExpandGroup.xlsx");
public void ExpandGroup(GroupByType groupBy, ExpandCollapseFlags flags)
Parameters
groupBy
GroupByTypeThis parameter specifies whether the grouping should be performed by rows or by columns.
flags
ExpandCollapseFlagsAdditional option flags.
ExportDataTable(ExportTableOptions)
public DataTable ExportDataTable(ExportTableOptions options)
Parameters
options
ExportTableOptions
Returns
FindAll(bool)
protected CellRange[] FindAll(bool findValue)
Parameters
findValue
bool
Returns
FindAll(DateTime)
protected CellRange[] FindAll(DateTime findValue)
Parameters
findValue
DateTime
Returns
FindAll(double, FindType)
protected CellRange[] FindAll(double findValue, FindType flags)
Parameters
Returns
FindAll(string, FindType)
protected CellRange[] FindAll(string findValue, FindType flags)
Parameters
Returns
FindAll(string, FindType, ExcelFindOptions)
protected CellRange[] FindAll(string findValue, FindType flags, ExcelFindOptions findOptions)
Parameters
findValue
stringflags
FindTypefindOptions
ExcelFindOptions
Returns
FindAll(TimeSpan)
protected CellRange[] FindAll(TimeSpan findValue)
Parameters
findValue
TimeSpan
Returns
FindFirst(bool)
protected IXLSRange FindFirst(bool findValue)
Parameters
findValue
bool
Returns
FindFirst(DateTime)
protected IXLSRange FindFirst(DateTime findValue)
Parameters
findValue
DateTime
Returns
FindFirst(double, FindType)
protected IXLSRange FindFirst(double findValue, FindType flags)
Parameters
Returns
FindFirst(string, FindType)
protected IXLSRange FindFirst(string findValue, FindType flags)
Parameters
Returns
FindFirst(TimeSpan)
protected IXLSRange FindFirst(TimeSpan findValue)
Parameters
findValue
TimeSpan
Returns
FindWorksheet(string)
protected IWorksheet FindWorksheet(string sheetName)
Parameters
sheetName
string
Returns
FreezePanes()
Freezes panes at the current range in the worksheet. current range should be single cell range.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Applying Freeze Pane to the sheet by specifying a cell
worksheet.Range["B2"].FreezePanes();
//Save to file
workbook.SaveToFile("FreezePanes.xlsx");
public void FreezePanes()
GetConditionFormatsStyle()
Get the calculated condition format style of current Range. If style of every cell is not same, return null. If current range without condition format, return null.
public CellStyle GetConditionFormatsStyle()
Returns
GetEnumerator()
public IEnumerator<IXLSRange> GetEnumerator()
Returns
GetNewRangeLocation(Dictionary<string, string>, out string)
Gets new range location.
public string GetNewRangeLocation(Dictionary<string, string> names, out string sheetName)
Parameters
names
Dictionary<string, string>Worksheet names.
sheetName
string
Returns
- string
New name.
GetRectangles()
Gets rectangle information of current range.
public Rectangle[] GetRectangles()
Returns
- Rectangle[]
Rectangles information
GetRectanglesCount()
Returns number of rectangles..
public int GetRectanglesCount()
Returns
- int
Number of rectangles.
GroupByColumns(bool)
Groups columns.
public CellRange GroupByColumns(bool isCollapsed)
Parameters
isCollapsed
boolIndicates whether group should be collapsed.
Returns
GroupByRows(bool)
Groups row.
public CellRange GroupByRows(bool isCollapsed)
Parameters
isCollapsed
boolIndicates whether group should be collapsed.
Returns
InfillCells()
protected void InfillCells()
Intersect(IXLSRange)
Returns intersection of this range with the specified one.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Get intersect range
IXLSRange range = worksheet.Range["A16:C16"];
IXLSRange commonRange = worksheet.Range["B16:D16"].Intersect(range);
//Save to file
workbook.SaveToFile("Intersect.xlsx");
public IXLSRange Intersect(IXLSRange range)
Parameters
range
IXLSRangeThe Range with which to intersect.
Returns
- IXLSRange
Range intersection. If there is no intersection, NULL is returned.
IsIntersect(IXLSRange)
public bool IsIntersect(IXLSRange range)
Parameters
range
IXLSRange
Returns
MeasureString(string)
Measures size of the string.
public SizeF MeasureString(string measureString)
Parameters
measureString
stringString to measure.
Returns
- SizeF
Size of the string.
Merge()
Creates a merged cell from the specified Range object.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Set text
worksheet["A1"].Text = "Merged cell";
//Merge cells
worksheet["A1:B1"].Merge();
//Save to file
workbook.SaveToFile("Merge.xlsx");
public void Merge()
Merge(IXLSRange)
Creates a merged cell from the specified Range object.
public IXLSRange Merge(IXLSRange range)
Parameters
range
IXLSRangeThe Range to merge with.
Returns
- IXLSRange
Merged ranges or null if wasn't able to merge ranges.
Merge(bool)
Creates a merged cell from the specified Range object.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Set text
worksheet["A1"].Text = "Merged cell";
worksheet["B1"].Text = "sample";
//Merge cells
worksheet["A1:B1"].Merge(true);
//Save to file
workbook.SaveToFile("Merge.xlsx");
public void Merge(bool clearCells)
Parameters
clearCells
boolIndicates whether to clear unnecessary cells.
MoveTo(IXLSRange)
protected void MoveTo(IXLSRange destination)
Parameters
destination
IXLSRange
MoveTo(IXLSRange, bool)
protected void MoveTo(IXLSRange destination, bool bUpdateFormula)
Parameters
PartialClear()
Partially clear range.
public void PartialClear()
RemoveCombinedRange(CellRange)
public void RemoveCombinedRange(CellRange cr)
Parameters
cr
CellRange
RemoveMergeComment()
public void RemoveMergeComment()
ReparseFormulaString()
Reparses formula.
public void ReparseFormulaString()
Replace(string, DataColumn, bool)
Replaces cells' values with new data.
public void Replace(string oldValue, DataColumn newValues, bool isFieldNamesShown)
Parameters
oldValue
stringValue to search for.
newValues
DataColumnDataColumn to replace.
isFieldNamesShown
boolIndicates whether to insert values vertically or horizontally.
Replace(string, DataTable, bool)
Replaces cells' values with new data.
public void Replace(string oldValue, DataTable newValues, bool isFieldNamesShown)
Parameters
oldValue
stringValue to search for.
newValues
DataTableThe replacement value.
isFieldNamesShown
bool
Replace(string, DateTime)
Replaces cells' values with new data.
public void Replace(string oldValue, DateTime newValue)
Parameters
Replace(string, double)
Replaces cells' values with new data.
public void Replace(string oldValue, double newValue)
Parameters
Replace(string, double[], bool)
Replaces cells' values with new data.
public void Replace(string oldValue, double[] newValues, bool isVertical)
Parameters
Replace(string, int[], bool)
Replaces cells' values with new data.
public void Replace(string oldValue, int[] newValues, bool isVertical)
Parameters
oldValue
stringValue to search for.
newValues
int[]The replacement value.
isVertical
boolIndicates whether to insert values vertically or horizontally.
Replace(string, string)
Replaces cells' values with new data.
public void Replace(string oldValue, string newValue)
Parameters
Replace(string, string[], bool)
Replaces cells' values with new data.
public void Replace(string oldValue, string[] newValues, bool isVertical)
Parameters
oldValue
stringValue to search for.
newValues
string[]The replacement value.
isVertical
boolIndicates whether to insert values vertically or horizontally.
SetAutoFormat(AutoFormatType)
[Obsolete("the method is not implemented")]
public void SetAutoFormat(AutoFormatType format)
Parameters
format
AutoFormatType
SetAutoFormat(AutoFormatType, AutoFormatOptions)
[Obsolete("the method is not implemented")]
public void SetAutoFormat(AutoFormatType format, AutoFormatOptions options)
Parameters
format
AutoFormatTypeoptions
AutoFormatOptions
SetBorderToSingleCell(BordersLineType, LineStyleType, ExcelColors)
protected void SetBorderToSingleCell(BordersLineType borderIndex, LineStyleType borderLine, ExcelColors borderColor)
Parameters
borderIndex
BordersLineTypeborderLine
LineStyleTypeborderColor
ExcelColors
SetDataValidation(XlsValidation)
public void SetDataValidation(XlsValidation dv)
Parameters
SetExtendedFormatIndex(int)
public void SetExtendedFormatIndex(int index)
Parameters
index
int
SetRowHeight(double, bool)
public void SetRowHeight(double rowHeight, bool bIsBadFontHeight)
Parameters
SetSharedFormula(string, int, int)
public void SetSharedFormula(string sharedFormula, int rowNumber, int columnNumber)
Parameters
TextPartReplace(string, string)
Replaces cell's part text and reserve text's format.
public void TextPartReplace(string oldPartValue, string newPartValue)
Parameters
oldPartValue
stringPart value of cell's text to search for.
newPartValue
stringThe replacement value.
UnMerge()
Separates a merged area into individual cells.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Set text
worksheet["A1"].Text = "Merged cell";
//Merge cells
worksheet["A1:B1"].Merge(true);
//Unmerge cells
worksheet["A1:B1"].UnMerge();
//Save to file
workbook.SaveToFile("UnMerge.xlsx");
public void UnMerge()
UngroupByColumns()
Ungroups column.
public CellRange UngroupByColumns()
Returns
UngroupByRows()
Ungroups row.
public CellRange UngroupByRows()
Returns
Union(CellRange)
public RangesCollection Union(CellRange range)
Parameters
range
CellRange
Returns
UpdateRange(int, int, int, int)
Update region of range
public void UpdateRange(int startRow, int startColumn, int endRow, int endColumn)