Cell class

Cell class

Encapsulates the object that represents a single Workbook cell.

The Cell type exposes the following members:

Properties

PropertyDescription
worksheetGets the parent worksheet.
date_time_valueGets the DateTime value contained in the cell.
rowGets row number (zero based) of the cell.
columnGets column number (zero based) of the cell.
is_formulaRepresents if the specified cell contains formula.
typeRepresents cell value type.
nameGets the name of the cell.
is_error_valueChecks if the value of this cell is an error.
is_numeric_valueIndicates whether the value of this cell is numeric(int, double and datetime)
string_valueGets 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).
string_value_without_formatGets cell’s value as string without any format.
number_category_typeRepresents the category type of this cell’s number formatting.
display_string_valueGets the formatted string value of this cell by cell’s display style.
int_valueGets the integer value contained in the cell.
double_valueGets the double value contained in the cell.
float_valueGets the float value contained in the cell.
bool_valueGets the boolean value contained in the cell.
has_custom_styleIndicates whether this cell has custom style settings(different from the default one inherited
from corresponding row, column, or workbook).
shared_style_indexGets cell’s shared style index in the style pool.
formulaGets or sets a formula of the Cell.
formula_localGet the locale formatted formula of the cell.
r1c1_formulaGets or sets a R1C1 formula of the Cell.
contains_external_linkIndicates whether this cell contains an external link.
Only applies when the cell is a formula cell.
is_array_headerIndicates the cell’s formula is an array formula
and it is the first cell of the array.
is_dynamic_array_formulaIndicates whether the cell’s formula is dynamic array formula(true) or legacy array formula(false).
is_array_formulaIndicates whether the cell formula is an array formula.
is_in_arrayIndicates whether the cell formula is an array formula.
is_shared_formulaIndicates whether the cell formula is part of shared formula.
is_table_formulaIndicates whether this cell is part of table formula.
is_in_tableIndicates whether this cell is part of table formula.
valueGets/sets the value contained in this cell.
is_style_setIndicates if the cell’s style is set. If return false, it means this cell has a default cell format.
is_mergedChecks if a cell is part of a merged range or not.
commentGets the comment of this cell.
html_stringGets and sets the html string which contains data and some formats in this cell.
is_check_box_styleIndicates whether setting this cell as a check box.
embedded_imageGets and sets the embeddedn image in the cell.

Methods

MethodDescription
put_valuePuts a boolean value into the cell.
put_valuePuts an integer value into the cell.
put_valuePuts a double value into the cell.
put_valuePuts a value into the cell, if appropriate the value will be converted to other data type and cell’s number format will be reset.
put_valuePuts a string value into the cell and converts the value to other data type if appropriate.
put_valuePuts a string value into the cell.
put_valuePuts a DateTime value into the cell.
put_valuePuts an object value into the cell.
get_display_styleGets 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().
get_display_styleGets the display style of the cell.
If the cell is conditional formatted, the display style is not same as the cell.GetStyle().
get_styleGets the cell style.
get_styleIf checkBorders is true, check whether other cells’ borders will effect the style of this cell.
set_styleSets the cell style.
set_styleApply the changed property of style to the cell.
set_styleApply the cell style based on flags.
set_formulaSet the formula and the value(calculated result) of the formula.
set_formulaSet the formula and the value(calculated result) of the formula.
set_formulaSet the formula and the value of the formula.
set_formulaSet the formula and the value(calculated result) of the formula.
set_array_formulaSets an array formula to a range of cells.
set_array_formulaSets an array formula(legacy array formula entered via CTRL+SHIFT+ENTER in ms excel) to a range of cells.
set_array_formulaSets an array formula to a range of cells.
set_array_formulaSets an array formula to a range of cells.
set_shared_formulaSets a formula to a range of cells.
set_shared_formulaSets shared formulas to a range of cells.
set_shared_formulaSets shared formulas to a range of cells.
set_shared_formulaSets shared formulas to a range of cells.
get_leafsGet all cells which reference to this cell directly and need to be updated when this cell is modified.
get_leafsGet all cells which will be updated when this cell is modified.
set_dynamic_array_formulaSets dynamic array formula and make the formula spill into neighboring cells if possible.
set_dynamic_array_formulaSets dynamic array formula and make the formula spill into neighboring cells if possible.
set_dynamic_array_formulaSets dynamic array formula and make the formula spill into neighboring cells if possible.
set_table_formulaCreate two-variable data table for given range starting from this cell.
set_table_formulaCreate one-variable data table for given range starting from this cell.
set_table_formulaCreate two-variable data table for given range starting from this cell.
set_table_formulaCreate one-variable data table for given range starting from this cell.
get_charactersReturns all Characters objects
that represents a range of characters within the cell text.
get_charactersReturns all Characters objects
that represents a range of characters within the cell text.
calculateCalculates the formula of the cell.
get_string_valueGets the string value by specific formatted strategy.
get_width_of_valueGets the width of the value in unit of pixels.
get_height_of_valueGets the height of the value in unit of pixels.
get_format_conditionsGets format conditions which applies to this cell.
get_formulaGet the formula of this cell.
get_precedentsGets all references appearing in this cell’s formula.
get_dependentsGet all cells whose formula references to this cell directly.
get_precedents_in_calculationGets all precedents(reference to cells in current workbook) used by this cell’s formula while calculating it.
get_dependents_in_calculationGets all cells whose calculated result depends on this cell.
get_array_rangeGets the array range if the cell’s formula is an array formula.
remove_array_formulaRemove array formula.
copyCopies data from a source cell.
charactersReturns a Characters object that represents a range of characters within the cell text.
replaceReplace text of the cell with options.
insert_textInsert some characters to the cell.
If the cell is rich formatted, this method could keep the original formatting.
is_rich_textIndicates whether the string value of this cell is a rich formatted text.
set_charactersSets rich text format of the cell.
get_merged_rangeReturns a Range object which represents a merged range.
get_html_stringGets the html string which contains data and some formats in this cell.
to_jsonConvert Cell to JSON struct data.
equalsChecks whether this object refers to the same cell with another cell object.
get_conditional_formatting_resultGet the result of the conditional formatting.
get_validationGets the validation applied to this cell.
get_validation_valueGets the value of validation which applied to this cell.
get_tableGets the table which contains this cell.
get_rich_valueGets rich value of the cell.

Example

from aspose.cells import TextAlignmentType, Workbook
from aspose.pydrawing import Color

excel = Workbook()
cells = excel.worksheets[0].cells
# Put a string into a cell
cell = cells.get(0, 0)
cell.put_value("Hello")
first = cell.string_value
# Put an integer into a cell
cell = cells.get("B1")
cell.put_value(12)
second = cell.int_value
# Put a double into a cell
cell = cells.get(0, 2)
cell.put_value(-1.234)
third = cell.double_value
# Put a formula into a cell
cell = cells.get("D1")
cell.formula = "=B1 + C1"
# Put a combined formula: "sum(average(b1,c1), b1)" to cell at b2
cell = cells.get("b2")
cell.formula = "=sum(average(b1,c1), b1)"
# Set style of a cell
style = cell.get_style()
# Set background color
style.background_color = Color.yellow
# Set format of a cell
style.font.name = "Courier New"
style.vertical_alignment = TextAlignmentType.TOP
cell.set_style(style)

See Also