Class CellRange
public class CellRange : XlsRange, ICombinedRange, IXLSRange, IExcelApplication, IEnumerable<IXLSRange>, IEnumerable, IDisposable
- Inheritance
-
CellRange
- Implements
- Inherited Members
Properties
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");
public BordersCollection Borders { get; }
Property Value
CellList
Returns a Range object that represents the cells in the specified range.
//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");
public List<CellRange> CellList { get; }
Property Value
Cells
Returns a Range object that represents the cells in the specified range.
[Obsolete("Please use CellList")]
public CellRange[] Cells { get; }
Property Value
Columns
Returns a Range object that represents 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");
public CellRange[] Columns { get; }
Property Value
Comment
Returns a Comment object that represents the comment associated with the cell in the upper-left corner of the range.
//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");
public ExcelComment Comment { get; }
Property Value
EndCell
Returns a Range object that represents the cell at the end of the region that contains the source range.
public CellRange EndCell { get; }
Property Value
EntireColumn
Returns a Range object that represents the entire column (or columns) that contains the specified range.
public CellRange EntireColumn { get; }
Property Value
EntireRow
Returns a Range object that represents the entire row (or rows) that contains the specified range.
public CellRange EntireRow { get; }
Property Value
this[int, int]
Gets cell range. Row and column indexes are one-based.
public CellRange this[int row, int column] { get; set; }
Parameters
Property Value
this[int, int, int, int]
Gets cell range. Row and column indexes are one-based.
public CellRange this[int row, int column, int lastRow, int lastColumn] { get; }
Parameters
Property Value
this[string]
Gets cell range.
public CellRange this[string name] { get; }
Parameters
name
string
Property Value
this[string, bool]
Gets cell range
public CellRange this[string name, bool IsR1C1Notation] { get; }
Parameters
Property Value
MergeArea
Returns a Range object that represents the merged range containing the specified cell.
//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);
public CellRange MergeArea { get; }
Property Value
RichText
Returns a RichTextString object that represents the rich text style.
//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");
public RichText RichText { get; }
Property Value
Rows
Returns the number of the first row of the first area in the 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");
public CellRange[] Rows { get; }
Property Value
Style
Returns a Style object that represents the style of the specified range.
//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");
public CellStyle Style { get; set; }
Property Value
Worksheet
Returns a worksheet object that represents the worksheet containing the specified range.
public Worksheet Worksheet { get; }
Property Value
Methods
Activate()
Active single cell in the worksheet
public CellRange Activate()
Returns
AddComment()
Adds a 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");
public ExcelComment AddComment()
Returns
- ExcelComment
Created comment or exists one.
AddComment(ExcelComment)
Adds a comment to the range.
public void AddComment(ExcelComment comment)
Parameters
comment
ExcelCommentComment to add
Clone(object, Dictionary<string, string>, Workbook)
Clones current IXLSRange.
public CellRange Clone(object parent, Dictionary<string, string> rangeNames, Workbook book)
Parameters
parent
objectParent object.
rangeNames
Dictionary<string, string>new names.
book
WorkbookParent workbook.
Returns
- CellRange
Cloned instance.
Copy(CellRange)
Copies the range to the specified range.
public CellRange Copy(CellRange destRange)
Parameters
destRange
CellRangeDestination range
Returns
- CellRange
Destination range
Copy(CellRange, CopyRangeOptions)
Copies the range to the specified range.
public CellRange Copy(CellRange destRange, CopyRangeOptions copyOptions)
Parameters
destRange
CellRangeDestination range.
copyOptions
CopyRangeOptionsCopy options.
Returns
Copy(CellRange, bool)
Copies the range to the specified range.
public CellRange Copy(CellRange destRange, bool updateReference)
Parameters
Returns
Copy(CellRange, bool, bool)
Copies the range to the specified range.
public CellRange Copy(CellRange destRange, bool updateReference, bool copyStyles)
Parameters
destRange
CellRangeDestination range.
updateReference
boolIndicates whether to update reference cells.
copyStyles
boolIndicates whether to copy styles.
Returns
- CellRange
Destination range
FindAll(string, FindType, ExcelFindOptions)
Finds the all ranges with specified string value.
public CellRange[] FindAll(string findValue, FindType flags, ExcelFindOptions findOptions)
Parameters
findValue
stringValue to search.
flags
FindTypeType of value to search.
findOptions
ExcelFindOptionsWay to search.
Returns
- CellRange[]
Found ranges
FindAllBool(bool)
Finds the cell with the input bool.
public CellRange[] FindAllBool(bool boolValue)
Parameters
boolValue
boolBool value to search for
Returns
- CellRange[]
Found ranges
FindAllDateTime(DateTime)
Finds the cell with the input datetime.
public CellRange[] FindAllDateTime(DateTime dateTimeValue)
Parameters
dateTimeValue
DateTimeDateTime value to search for
Returns
- CellRange[]
Found ranges
FindAllNumber(double, bool)
Finds the cell with the input double.
public CellRange[] FindAllNumber(double doubleValue, bool formulaValue)
Parameters
doubleValue
doubleDouble value to search for
formulaValue
boolIndicates whether to find formula value
Returns
- CellRange[]
Found ranges
FindAllString(string, bool, bool)
Finds the cell with the input string.
public CellRange[] FindAllString(string stringValue, bool formula, bool formulaValue)
Parameters
stringValue
stringString value to search for
formula
boolIndicates whether include formula
formulaValue
boolIndicates whether include formula value
Returns
- CellRange[]
Found ranges
FindAllTimeSpan(TimeSpan)
Finds the cell with input timespan
public CellRange[] FindAllTimeSpan(TimeSpan timeSpanValue)
Parameters
timeSpanValue
TimeSpantime span value to search for
Returns
- CellRange[]
Found ranges
FindBool(bool)
Finds the cell with the input bool.
public CellRange FindBool(bool boolValue)
Parameters
boolValue
boolBool value to search for
Returns
- CellRange
Found range
FindDateTime(DateTime)
Finds the cell with the input datetime.
public CellRange FindDateTime(DateTime dateTimeValue)
Parameters
dateTimeValue
DateTimeDatetime value to search for
Returns
- CellRange
Found range
FindNumber(double, bool)
Finds the cell with the input double.
public CellRange FindNumber(double doubleValue, bool formulaValue)
Parameters
doubleValue
doubleDouble value to search for
formulaValue
boolIndicates whether includes formula value to search for
Returns
- CellRange
Found range
FindString(string, bool, bool)
Finds the cell with the input string.
public CellRange FindString(string stringValue, bool formula, bool formulaValue)
Parameters
stringValue
stringString value to search for
formula
boolIndicates whether includes formula to search for
formulaValue
boolIndicates whether includes formula value to search for
Returns
- CellRange
Found range
FindTimeSpan(TimeSpan)
Finds the cell with the input time span.
public CellRange FindTimeSpan(TimeSpan timeSpanValue)
Parameters
timeSpanValue
TimeSpanTime span value to search for.
Returns
- CellRange
Found range.
GetDependentRanges(bool)
public CellRange[] GetDependentRanges(bool isAll)
Parameters
isAll
bool
Returns
GetReferRanges()
public ReferRangeArea[] GetReferRanges()
Returns
Intersect(CellRange)
Get intersection range with the specified range.
public CellRange Intersect(CellRange range)
Parameters
range
CellRangeRange which to intersect.
Returns
- CellRange
Range intersection.
Merge(CellRange)
Creates a merged cell from the specified Range object.
//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");
public CellRange Merge(CellRange range)
Parameters
range
CellRangeThe Range to merge with.
Returns
- CellRange
Merged ranges.
Move(CellRange)
Moves the cells to the specified Range.
public void Move(CellRange destRange)
Parameters
destRange
CellRange
Move(CellRange, bool, bool)
Moves the cells to the specified Range.
public void Move(CellRange destRange, bool copyStyle, bool updateReference)
Parameters
destRange
CellRangecopyStyle
boolupdateReference
boolIndicates whether to update reference range.
SetDataValidation(Validation)
Sets data validation for the range.
public void SetDataValidation(Validation dataValidation)
Parameters
dataValidation
Validation