Interface IXLSRange
Represents a cell, row, column, selection of cells containing one or more contiguous blocks of cells, or a 3-D range.
public interface IXLSRange : IExcelApplication, IEnumerable
- Inherited Members
Properties
BooleanValue
Gets / sets boolean value that is contained by this 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;
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 worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Set text
worksheet["C2"].Text = "Sample";
//Set borders
IBorders borders = worksheet["C2"].Borders;
//Set line style
borders[BordersLineType.EdgeTop].LineStyle = LineStyleType.Thin;
borders[BordersLineType.EdgeBottom].LineStyle = LineStyleType.Thin;
//Set border color
borders[BordersLineType.EdgeTop].Color = Color.Red;
borders[BordersLineType.EdgeBottom].Color = Color.Red;
//Save to file
workbook.SaveToFile("CellFormats.xlsx");
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");
BuiltInStyles? BuiltInStyle { get; set; }
Property Value
CellList
Returns a Range object that represents the cells in the specified range.
Read-only.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Set text. The content contained by ![CDATA[]] will be expressed as plain text
ListCellRange cells = worksheet["A1:E8"].CellList;
//Do some manipulations
foreach (CellRange Range in cells)
Range.Text = Range.RangeAddressLocal;
//Save to file
workbook.SaveToFile("CellList.xlsx");
List<CellRange> CellList { get; }
Property Value
CellStyleName
Returns name of the Style object that represents the style of the specified
range. Read/write String.
//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);
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")]
CellRange[] Cells { get; }
Property Value
Column
Returns the number of the first column in the first area in the specified
range. Read-only.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Get specific column
int firstColumn = worksheet["E1:R3"].Column;
int Column { get; }
Property Value
ColumnGroupLevel
Column group level. Read-only. -1 - Not all columns in the range have same group level. 0 - No grouping, 1 - 7 - Group level.
int ColumnGroupLevel { get; }
Property Value
ColumnWidth
Returns or sets the width of all columns in the specified range.
Read/write Double.
//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");
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 worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Set columns
IXLSRange[] columns = worksheet["A1:E8"].Columns;
//Do some manipulations
foreach (IXLSRange column in columns)
column.Text = column.RangeAddressLocal;
//Save to file
workbook.SaveToFile("Columns.xlsx");
IXLSRange[] Columns { get; }
Property Value
Comment
Comment assigned to the range. Read-only.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Adding comments to a cell
worksheet.Range["A1"].AddComment().Text = "Comments";
//Add Rich Text Comments
CellRange range = worksheet.Range["A6"];
range.AddComment().RichText.Text = "RichText";
IRichTextString rtf = range.Comment.RichText;
//Formatting first 4 characters
IFont redFont = workbook.CreateFont();
redFont.IsBold = true;
redFont.Color = Color.Red;
rtf.SetFont(0, 3, redFont);
//Save to file
workbook.SaveToFile("DataValidation.xlsx");
ICommentShape Comment { get; }
Property Value
ConditionalFormats
Collection of conditional formats.
ConditionalFormats ConditionalFormats { get; }
Property Value
Count
Returns the number of objects in the collection. Read-only.
int Count { get; }
Property Value
DataValidation
Data validation for the range.
//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");
Validation DataValidation { get; }
Property Value
DateTimeValue
Gets / sets DateTime contained by this cell. Read-write DateTime.
//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");
DateTime DateTimeValue { get; set; }
Property Value
EndCell
Returns a Range object that represents the cell at the end of the region that contains the source range.
IXLSRange EndCell { get; }
Property Value
EntireColumn
Returns a Range object that represents the entire column (or columns) that contains the specified range. Read-only.
IXLSRange EntireColumn { get; }
Property Value
EntireRow
Returns a Range object that represents the entire row (or rows) that contains the specified range. Read-only.
IXLSRange EntireRow { get; }
Property Value
EnvalutedValue
Returns the calculated value of a formula using the most current inputs.
//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);
string EnvalutedValue { get; }
Property Value
ErrorValue
Gets / sets error value that is contained by this range.
string ErrorValue { get; set; }
Property Value
Formula
Returns or sets the object's formula in A1-style notation and in the language of the macro. Read/write Variant.
string Formula { get; set; }
Property Value
FormulaArray
Represents array-entered formula.
Visit http://www.cpearson.com/excel/array.htm for more information.
//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");
string FormulaArray { get; set; }
Property Value
FormulaArrayR1C1
Returns or sets the formula array for the range, using R1C1-style notation.
string FormulaArrayR1C1 { get; set; }
Property Value
FormulaBoolValue
Returns the calculated value of the formula as a boolean.
bool FormulaBoolValue { get; set; }
Property Value
FormulaDateTime
Get / set formula DateTime value contained by this cell. DateTime.MinValue if not all cells of the range have same DateTime value.
DateTime FormulaDateTime { get; set; }
Property Value
FormulaErrorValue
Returns the calculated value of the formula as a string.
string FormulaErrorValue { get; set; }
Property Value
FormulaNumberValue
Gets / sets number value evaluated by formula.
double FormulaNumberValue { get; set; }
Property Value
FormulaR1C1
Returns or sets the formula for the range, using R1C1-style notation.
string FormulaR1C1 { get; set; }
Property Value
FormulaStringValue
Gets / sets string value evaluated by formula.
string FormulaStringValue { get; set; }
Property Value
HasBoolean
Indicates whether range contains bool value. Read-only.
//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");
bool HasBoolean { 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.
bool HasDataValidation { get; }
Property Value
HasDateTime
Indicates whether range contains DateTime value. Read-only.
//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");
bool HasDateTime { get; }
Property Value
HasError
Indicates whether range contains error value.
bool HasError { get; }
Property Value
HasExternalFormula
Indicates is current range has external formula. Read-only.
bool HasExternalFormula { get; }
Property Value
HasFormula
True if all cells in the range contain formulas; False if at least one of the cells in the range doesn't contain a formula. Read-only Boolean.
bool HasFormula { get; }
Property Value
HasFormulaArray
Indicates whether range contains array-entered formula. Read-only.
bool HasFormulaArray { get; }
Property Value
HasFormulaBoolValue
Indicates if current range has formula bool value. Read only.
bool HasFormulaBoolValue { get; }
Property Value
HasFormulaDateTime
Indicates if current range has formula value formatted as DateTime. Read-only.
bool HasFormulaDateTime { get; }
Property Value
HasFormulaErrorValue
Indicates if current range has formula error value. Read only.
bool HasFormulaErrorValue { get; }
Property Value
HasFormulaNumberValue
Indicates if the current range has formula number value. Read-only.
bool HasFormulaNumberValue { get; }
Property Value
HasFormulaStringValue
Indicates if the current range has formula string value. Read-only.
bool HasFormulaStringValue { get; }
Property Value
HasMerged
Indicates whether this range is part of merged range. Read-only.
//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);
bool HasMerged { get; }
Property Value
HasNumber
Indicates whether the range contains number. Read-only.
//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");
bool HasNumber { get; }
Property Value
HasRichText
Indicates whether cell contains formatted 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");
bool HasRichText { get; }
Property Value
HasString
Indicates whether the range contains String. Read-only.
bool HasString { get; }
Property Value
HasStyle
Indicates whether range has default style. False means default style.
Read-only.
//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");
bool HasStyle { get; }
Property Value
HorizontalAlignment
Returns or sets the horizontal alignment for the specified object.
Read/write HorizontalAlignType.
//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");
HorizontalAlignType HorizontalAlignment { get; set; }
Property Value
HtmlString
Gets and sets the html string which contains data and some formattings in this cell.
string HtmlString { get; set; }
Property Value
Hyperlinks
Returns hyperlinks for this range.
IHyperLinks Hyperlinks { get; }
Property Value
IgnoreErrorOptions
Represents ignore error options.
IgnoreErrorType IgnoreErrorOptions { get; set; }
Property Value
IndentLevel
Returns or sets the indent level for the cell or range. Can be an
integer from 0 to 15. Read/write Integer.
//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");
int IndentLevel { get; set; }
Property Value
IsBlank
Indicates whether the range is blank. Read-only.
bool IsBlank { get; }
Property Value
IsFormulaHidden
True if the formula will be hidden when the worksheet is protected. False if at least part of formula in the range is not hidden.
bool IsFormulaHidden { get; set; }
Property Value
IsGroupedByColumn
Indicates whether this range is grouped by column. Read-only.
bool IsGroupedByColumn { get; }
Property Value
IsGroupedByRow
Indicates whether this range is grouped by row. Read-only.
bool IsGroupedByRow { get; }
Property Value
IsInitialized
Indicates whether cell is initialized. Read-only.
bool IsInitialized { get; }
Property Value
IsStringsPreserved
Indicates whether all values in the range are preserved as strings.
bool? IsStringsPreserved { get; set; }
Property Value
- bool?
IsWrapText
True if Microsoft Excel wraps the text in the object.
Read/write Boolean.
//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");
bool IsWrapText { get; set; }
Property Value
this[int, int]
Gets / sets cell by row and column index. Row and column indexes are one-based.
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.
IXLSRange this[int row, int column, int lastRow, int lastColumn] { get; }
Parameters
Property Value
this[string]
Get cell range. Read-only.
IXLSRange this[string name] { get; }
Parameters
name
string
Property Value
this[string, bool]
Gets cell range. Read-only.
IXLSRange this[string name, bool IsR1C1Notation] { get; }
Parameters
Property Value
LastColumn
Returns last column of the range. Read-only.
int LastColumn { get; set; }
Property Value
LastRow
Returns last row of the range. Read-only.
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 worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Set text
worksheet["C2"].Text = "Sample text in cell";
//Set merge
worksheet["C2:D3"].Merge();
//Check merge area
Console.Write(worksheet["C2"].MergeArea.AddressLocal);
IXLSRange MergeArea { get; }
Property Value
NumberFormat
Format of current cell. Analog of Style.NumberFormat property.
//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");
string NumberFormat { get; set; }
Property Value
NumberText
Returns cell value after number format application. Read-only.
//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");
string NumberText { get; }
Property Value
NumberValue
Gets / sets double value of the range.
double NumberValue { get; set; }
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;
string RangeAddress { get; }
Property Value
RangeAddressLocal
Returns the range reference for the specified range in the language
of the user. Read-only String.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Get RangeAddressLocal
string address = worksheet.Range[3, 4].RangeAddressLocal;
string RangeAddressLocal { get; }
Property Value
RangeGlobalAddress
Returns range Address in format "'Sheet1'!$A$1".
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Get RangeAddress
string address = worksheet.Range[3, 4].RangeGlobalAddress;
string RangeGlobalAddress { get; }
Property Value
RangeR1C1Address
Returns the range reference using R1C1 notation.
Read-only String.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Get RangeR1C1Address
string address = worksheet.Range[3, 4].RangeR1C1Address;
string RangeR1C1Address { get; }
Property Value
RangeR1C1AddressLocal
Returns the range reference using R1C1 notation.
Read-only String.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Get RangeR1C1AddressLocal
string address = worksheet.Range[3, 4].RangeR1C1Address;
string RangeR1C1AddressLocal { get; }
Property Value
RichText
String with rich text formatting. Read-only.
//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 text";
//Set rich text font
IFont font = style.Font;
font.IsBold = true;
richText.SetFont(0, 5, font);
//Save to file
workbook.SaveToFile("RichText.xlsx");
IRichTextString RichText { get; }
Property Value
Row
Returns the number of the first row of the first area in the range. Read-only Long.
int Row { get; }
Property Value
RowGroupLevel
Row group level. Read-only. -1 - Not all rows in the range have same group level. 0 - No grouping, 1 - 7 - Group level.
int RowGroupLevel { get; }
Property Value
RowHeight
Returns the height of all the rows in the range specified,
measured in points. Returns Double.MinValue if the rows in the specified range
aren't all the same height. Read / write Double.
//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");
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 worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Set rows
IXLSRange[] rows = worksheet["A1:E8"].Rows;
//Do some manipulations
foreach (IXLSRange row in rows)
row.Text = row.RangeAddressLocal;
//Save to file
workbook.SaveToFile("Rows.xlsx");
IXLSRange[] Rows { get; }
Property Value
Style
Returns a Style object that represents the style of the specified
range. Read/write IStyle.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Set text
worksheet["C2"].Text = "Sample";
//Add and set style
CellStyle style = workbook.Styles.Add("BorderStyle");
style.Color = Color.Red;
worksheet["C2"].Style = style;
//Save to file
workbook.SaveToFile("Style.xlsx");
IStyle Style { get; set; }
Property Value
Text
Gets / sets string value of the range.
string Text { get; set; }
Property Value
TimeSpanValue
Gets / sets time value of the range.
TimeSpan TimeSpanValue { get; set; }
Property Value
Value
Returns or sets the value of the specified range.
Read/write Variant.
//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");
string Value { get; set; }
Property Value
Value2
Returns or sets the cell value. Read/write Variant.
The only difference between this property and the Value property is
that the Value2 property doesn't use the Currency and Date data 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);
object Value2 { get; set; }
Property Value
VerticalAlignment
Returns or sets the vertical alignment of the specified object.
Read/write VerticalAlignType.
//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");
VerticalAlignType VerticalAlignment { get; set; }
Property Value
Worksheet
Returns a Worksheet object that represents the worksheet containing the specified range. Read-only.
IWorksheet Worksheet { get; }
Property Value
Methods
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");
IXLSRange Activate(bool scroll)
Parameters
scroll
boolTrue to scroll to the cell
Returns
- IXLSRange
Returns the active cell.
AddComment()
Adds comment to the range.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Adding comments to a cell
ICommentShape comment = worksheet.Range["A1"].AddComment();
comment.Text= "Comments";
//Save to file
workbook.SaveToFile("AddComment.xlsx");
ICommentShape AddComment()
Returns
- ICommentShape
Range's comment.
AutoFitColumns()
Autofits all columns in the range.
//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");
void AutoFitColumns()
AutoFitRows()
Autofits all rows in the range.
//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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
void BorderNone()
Clear(ExcelClearOptions)
Clears the cell content, formats, comments based on clear option.
//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");
void Clear(ExcelClearOptions option)
Parameters
option
ExcelClearOptionsRepresents the clear options.
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");
void ClearContents()
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");
void CollapseGroup(GroupByType groupBy)
Parameters
groupBy
GroupByTypeThis parameter specifies whether the grouping should be performed by rows or by columns.
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");
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");
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)
DataTable ExportDataTable(ExportTableOptions options)
Parameters
options
ExportTableOptions
Returns
FreezePanes()
Freezes pane at the current 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");
void FreezePanes()
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");
IXLSRange Intersect(IXLSRange range)
Parameters
range
IXLSRangeThe Range with which to intersect.
Returns
- IXLSRange
Range intersection; if there is no intersection, NULL is returned.
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");
void Merge()
Merge(IXLSRange)
Returns merge of this range with the specified one.
//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//Merge range
worksheet["A2:B2"].Merge();
//Get mergable range
IXLSRange mergableRange = worksheet["A2"].MergeArea.Merge(worksheet["C2"]);
//Check mergable Area
Console.Write(mergableRange.RangeAddressLocal);
//Save to file
workbook.SaveToFile("Intersect.xlsx");
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");
void Merge(bool clearCells)
Parameters
clearCells
boolIndicates whether to clear unnecessary cells.
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");
void UnMerge()