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_value(self, bool_value)Puts a boolean value into the cell.
put_value(self, int_value)Puts an integer value into the cell.
put_value(self, double_value)Puts a double value into the cell.
put_value(self, string_value, is_converted, set_style)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.
put_value(self, string_value, is_converted)Puts a string value into the cell and converts the value to other data type if appropriate.
put_value(self, string_value)Puts a string value into the cell.
put_value(self, date_time)Puts a DateTime value into the cell.
put_value(self, object_value)Puts an object value into the cell.
get_display_style(self)Gets the display style of this cell.
get_display_style(self, include_merged_borders)Gets the display style of this cell.
get_display_style(self, adjacent_borders)Gets the display style of this cell.
get_style(self)Gets the cell style.
get_style(self, check_borders)If checkBorders is true, check whether other cells’ borders will effect the style of this cell.
set_style(self, style)Sets the cell style.
set_style(self, style, explicit_flag)Apply the changed property of style to the cell.
set_style(self, style, flag)Apply the cell style based on flags.
set_formula(self, formula, value)Set the formula and the value(calculated result) of the formula.
set_formula(self, formula, options)Set the formula and the value(calculated result) of the formula.
set_formula(self, formula, is_r1c1, is_local, value)Set the formula and the value of the formula.
set_formula(self, formula, options, value)Set the formula and the value(calculated result) of the formula.
set_array_formula(self, array_formula, row_number, column_number, is_r1c1, is_local)Sets an array formula to a range of cells.
set_array_formula(self, array_formula, row_number, column_number)Sets an array formula(legacy array formula entered via CTRL+SHIFT+ENTER in ms excel) to a range of cells.
set_array_formula(self, array_formula, row_number, column_number, options)Sets an array formula to a range of cells.
set_array_formula(self, array_formula, row_number, column_number, options, values)Sets an array formula to a range of cells.
set_shared_formula(self, shared_formula, row_number, column_number, is_r1c1, is_local)Sets a formula to a range of cells.
set_shared_formula(self, shared_formula, row_number, column_number)Sets shared formulas to a range of cells.
set_shared_formula(self, shared_formula, row_number, column_number, options)Sets shared formulas to a range of cells.
set_shared_formula(self, shared_formula, row_number, column_number, options, values)Sets shared formulas to a range of cells.
get_leafs(self)Get all cells which reference to this cell directly and need to be updated when this cell is modified.
get_leafs(self, recursive)Get all cells which will be updated when this cell is modified.
set_dynamic_array_formula(self, array_formula, options, calculate_value)Sets dynamic array formula and make the formula spill into neighboring cells if possible.
set_dynamic_array_formula(self, array_formula, options, values, calculate_range, calculate_value)Sets dynamic array formula and make the formula spill into neighboring cells if possible.
set_dynamic_array_formula(self, array_formula, options, values, calculate_range, calculate_value, copts)Sets dynamic array formula and make the formula spill into neighboring cells if possible.
set_table_formula(self, row_number, column_number, row_input_cell, column_input_cell, values)Create two-variable data table for given range starting from this cell.
set_table_formula(self, row_number, column_number, input_cell, is_row_input, values)Create one-variable data table for given range starting from this cell.
set_table_formula(self, row_number, column_number, row_index_of_row_input_cell, column_index_of_row_input_cell, row_index_of_column_input_cell, column_index_of_column_input_cell, values)Create two-variable data table for given range starting from this cell.
set_table_formula(self, row_number, column_number, row_index_of_input_cell, column_index_of_input_cell, is_row_input, values)Create one-variable data table for given range starting from this cell.
get_characters(self)Returns all Characters objects
that represents a range of characters within the cell text.
get_characters(self, flag)Returns all Characters objects
that represents a range of characters within the cell text.
calculate(self, options)Calculates the formula of the cell.
get_string_value(self, format_strategy)Gets the string value by specific formatted strategy.
get_width_of_value(self)Gets the width of the value in unit of pixels.
get_height_of_value(self)Gets the height of the value in unit of pixels.
get_format_conditions(self)Gets format conditions which applies to this cell.
get_formula(self, is_r1c1, is_local)Get the formula of this cell.
get_precedents(self)Gets all references appearing in this cell’s formula.
get_dependents(self, is_all)Get all cells whose formula references to this cell directly.
get_precedents_in_calculation(self)Gets all precedents(reference to cells in current workbook) used by this cell’s formula while calculating it.
get_dependents_in_calculation(self, recursive)Gets all cells whose calculated result depends on this cell.
get_array_range(self)Gets the array range if the cell’s formula is an array formula.
remove_array_formula(self, leave_normal_formula)Remove array formula.
copy(self, cell)Copies data from a source cell.
characters(self, start_index, length)Returns a Characters object that represents a range of characters within the cell text.
replace(self, place_holder, new_value, options)Replace text of the cell with options.
insert_text(self, index, text)Insert some characters to the cell.
If the cell is rich formatted, this method could keep the original formatting.
is_rich_text(self)Indicates whether the string value of this cell is a rich formatted text.
set_characters(self, characters)Sets rich text format of the cell.
get_merged_range(self)Returns a Range object which represents a merged range.
get_html_string(self, html5)Gets the html string which contains data and some formats in this cell.
to_json(self)Convert Cell to JSON struct data.
equals(self, cell)Checks whether this object refers to the same cell with another cell object.
get_conditional_formatting_result(self)Get the result of the conditional formatting.
get_validation(self)Gets the validation applied to this cell.
get_validation_value(self)Gets the value of validation which applied to this cell.
get_table(self)Gets the table which contains this cell.
get_rich_value(self)Gets 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