Class Cell

Cell class

Encapsulates the object that represents a single Workbook cell.

public class Cell

Properties

NameDescription
BoolValue { get; }Gets the boolean value contained in the cell.
Column { get; }Gets column number (zero based) of the cell.
Comment { get; }Gets the comment of this cell.
ContainsExternalLink { get; }Indicates whether this cell contains an external link. Only applies when the cell is a formula cell.
DateTimeValue { get; }Gets the DateTime value contained in the cell.
DisplayStringValue { get; }Gets the formatted string value of this cell by cell’s display style.
DoubleValue { get; }Gets the double value contained in the cell.
EmbeddedImage { get; set; }Gets and sets the embeddedn image in the cell.
FloatValue { get; }Gets the float value contained in the cell.
Formula { get; set; }Gets or sets a formula of the Cell.
FormulaLocal { get; set; }Get the locale formatted formula of the cell.
HasCustomStyle { get; }Indicates whether this cell has custom style settings(different from the default one inherited from corresponding row, column, or workbook).
HtmlString { get; set; }Gets and sets the html string which contains data and some formats in this cell.
IntValue { get; }Gets the integer value contained in the cell.
IsArrayFormula { get; }Indicates whether the cell formula is an array formula.
IsArrayHeader { get; }Indicates the cell’s formula is an array formula and it is the first cell of the array.
IsDynamicArrayFormula { get; }Indicates whether the cell’s formula is dynamic array formula(true) or legacy array formula(false).
IsErrorValue { get; }Checks if the value of this cell is an error.
IsFormula { get; }Represents if the specified cell contains formula.
IsInArray { get; }(Obsolete.) Indicates whether the cell formula is an array formula.
IsInTable { get; }(Obsolete.) Indicates whether this cell is part of table formula.
IsMerged { get; }Checks if a cell is part of a merged range or not.
IsNumericValue { get; }Indicates whether the value of this cell is numeric(int, double and datetime)
IsSharedFormula { get; }Indicates whether the cell formula is part of shared formula.
IsStyleSet { get; }Indicates if the cell’s style is set. If return false, it means this cell has a default cell format.
IsTableFormula { get; }Indicates whether this cell is part of table formula.
Name { get; }Gets the name of the cell.
NumberCategoryType { get; }Represents the category type of this cell’s number formatting.
R1C1Formula { get; set; }Gets or sets a R1C1 formula of the Cell.
Row { get; }Gets row number (zero based) of the cell.
SharedStyleIndex { get; }Gets cell’s shared style index in the style pool.
StringValue { get; }Gets the string value contained in the cell. If the type of this cell is string, then return the string value itself. For other cell types, the formatted string value (formatted with the specified style of this cell) will be returned. The formatted cell value is same with what you can get from excel when copying a cell as text(such as copying cell to text editor or exporting to csv).
StringValueWithoutFormat { get; }(Obsolete.) Gets cell’s value as string without any format.
Type { get; }Represents cell value type.
Value { get; set; }Gets/sets the value contained in this cell.
Worksheet { get; }Gets the parent worksheet.

Methods

NameDescription
Calculate(CalculationOptions)Calculates the formula of the cell.
Characters(int, int)Returns a Characters object that represents a range of characters within the cell text.
Copy(Cell)Copies data from a source cell.
Equals(Cell)Checks whether this object refers to the same cell with another cell object.
override Equals(object)Checks whether this object refers to the same cell with another.
GetArrayRange()Gets the array range if the cell’s formula is an array formula.
GetCharacters()Returns all Characters objects that represents a range of characters within the cell text.
GetCharacters(bool)Returns all Characters objects that represents a range of characters within the cell text.
GetConditionalFormattingResult()Get the result of the conditional formatting.
GetDependents(bool)Get all cells whose formula references to this cell directly.
GetDependentsInCalculation(bool)Gets all cells whose calculated result depends on this cell.
GetDisplayStyle()Gets the display style of the cell. If this cell is also affected by other settings such as conditional formatting, list objects, etc., then the display style may be different from cell.GetStyle().
GetDisplayStyle(bool)Gets the display style of the cell. If the cell is conditional formatted, the display style is not same as the cell.GetStyle().
GetFormatConditions()Gets format conditions which applies to this cell.
GetFormula(bool, bool)Get the formula of this cell.
override GetHashCode()Serves as a hash function for a particular type.
GetHeightOfValue()Gets the height of the value in unit of pixels.
GetHtmlString(bool)Gets the html string which contains data and some formats in this cell.
GetLeafs()(Obsolete.) Get all cells which reference to this cell directly and need to be updated when this cell is modified.
GetLeafs(bool)(Obsolete.) Get all cells which will be updated when this cell is modified.
GetMergedRange()Returns a Range object which represents a merged range.
GetPrecedents()Gets all references appearing in this cell’s formula.
GetPrecedentsInCalculation()Gets all precedents(reference to cells in current workbook) used by this cell’s formula while calculating it.
GetStringValue(CellValueFormatStrategy)Gets the string value by specific formatted strategy.
GetStyle()Gets the cell style.
GetStyle(bool)If checkBorders is true, check whether other cells’ borders will effect the style of this cell.
GetTable()Gets the table which contains this cell.
GetValidation()Gets the validation applied to this cell.
GetValidationValue()Gets the value of validation which applied to this cell.
GetWidthOfValue()Gets the width of the value in unit of pixels.
InsertText(int, string)Insert some characters to the cell. If the cell is rich formatted, this method could keep the original formatting.
IsRichText()Indicates whether the string value of this cell is a rich formatted text.
PutValue(bool)Puts a boolean value into the cell.
PutValue(DateTime)Puts a DateTime value into the cell.
PutValue(double)Puts a double value into the cell.
PutValue(int)Puts an integer value into the cell.
PutValue(object)Puts an object value into the cell.
PutValue(string)Puts a string value into the cell.
PutValue(string, bool)Puts a string value into the cell and converts the value to other data type if appropriate.
PutValue(string, bool, bool)Puts a value into the cell, if appropriate the value will be converted to other data type and cell’s number format will be reset.
RemoveArrayFormula(bool)Remove array formula.
Replace(string, string, ReplaceOptions)Replace text of the cell with options.
SetArrayFormula(string, int, int)Sets an array formula(legacy array formula entered via CTRL+SHIFT+ENTER in ms excel) to a range of cells.
SetArrayFormula(string, int, int, FormulaParseOptions)Sets an array formula to a range of cells.
SetArrayFormula(string, int, int, bool, bool)(Obsolete.) Sets an array formula to a range of cells.
SetArrayFormula(string, int, int, FormulaParseOptions, object[][])Sets an array formula to a range of cells.
SetCharacters(FontSetting[])Sets rich text format of the cell.
SetDynamicArrayFormula(string, FormulaParseOptions, bool)Sets dynamic array formula and make the formula spill into neighboring cells if possible.
SetDynamicArrayFormula(string, FormulaParseOptions, object[][], bool, bool)Sets dynamic array formula and make the formula spill into neighboring cells if possible.
SetDynamicArrayFormula(string, FormulaParseOptions, object[][], bool, bool, CalculationOptions)Sets dynamic array formula and make the formula spill into neighboring cells if possible.
SetFormula(string, object)Set the formula and the value(calculated result) of the formula.
SetFormula(string, FormulaParseOptions, object)Set the formula and the value(calculated result) of the formula.
SetFormula(string, bool, bool, object)(Obsolete.) Set the formula and the value of the formula.
SetSharedFormula(string, int, int)Sets shared formulas to a range of cells.
SetSharedFormula(string, int, int, FormulaParseOptions)Sets shared formulas to a range of cells.
SetSharedFormula(string, int, int, bool, bool)(Obsolete.) Sets a formula to a range of cells.
SetSharedFormula(string, int, int, FormulaParseOptions, object[][])Sets shared formulas to a range of cells.
SetStyle(Style)Sets the cell style.
SetStyle(Style, bool)Apply the changed property of style to the cell.
SetStyle(Style, StyleFlag)Apply the cell style based on flags.
SetTableFormula(int, int, string, bool, object[][])Create one-variable data table for given range starting from this cell.
SetTableFormula(int, int, string, string, object[][])Create two-variable data table for given range starting from this cell.
SetTableFormula(int, int, int, int, bool, object[][])Create one-variable data table for given range starting from this cell.
SetTableFormula(int, int, int, int, int, int, object[][])Create two-variable data table for given range starting from this cell.
ToJson()Convert Cell to JSON struct data.
override ToString()Returns a string represents the current Cell object.

Examples

[C#]

Workbook excel = new Workbook();
Cells cells = excel.Worksheets[0].Cells;

//Put a string into a cell
Cell cell = cells[0, 0];
cell.PutValue("Hello");

string first = cell.StringValue;
	
//Put an integer into a cell
cell = cells["B1"];
cell.PutValue(12);

int second = cell.IntValue;

//Put a double into a cell
cell = cells[0, 2];
cell.PutValue(-1.234);

double third = cell.DoubleValue;

//Put a formula into a cell
cell = cells["D1"];
cell.Formula = "=B1 + C1";

//Put a combined formula: "sum(average(b1,c1), b1)" to cell at b2
cell = cells["b2"];
cell.Formula = "=sum(average(b1,c1), b1)";

//Set style of a cell
Style style = cell.GetStyle();
//Set background color
style.BackgroundColor = Color.Yellow;
//Set format of a cell
style.Font.Name = "Courier New";
style.VerticalAlignment = TextAlignmentType.Top;
cell.SetStyle(style);



[Visual Basic]

Dim excel as Workbook = new Workbook()
Dim cells as Cells = exce.Worksheets(0).Cells

'Put a string into a cell
Dim cell as Cell = cells(0, 0)
cell.PutValue("Hello")

Dim first as String = cell.StringValue
	
//Put an integer into a cell
cell = cells("B1")
cell.PutValue(12)

Dim second as Integer = cell.IntValue

//Put a double into a cell
cell = cells(0, 2)
cell.PutValue(-1.234)

Dim third as Double = cell.DoubleValue

//Put a formula into a cell
cell = cells("D1")
cell.Formula = "=B1 + C1"

//Put a combined formula: "sum(average(b1,c1), b1)" to cell at b2
cell = cells("b2")
cell.Formula = "=sum(average(b1,c1), b1)"
	
//Set style of a cell
Dim style as Style = cell.GetStyle()

//Set background color
style.BackgroundColor = Color.Yellow
//Set font of a cell
style.Font.Name = "Courier New"
style.VerticalAlignment = TextAlignmentType.Top
cell.SetStyle(style)

See Also