Cell

Overview

Cell is a class in Aspose.Cells FOSS for Python.

Represents a single cell in a worksheet.

This class provides 20 methods for working with Cell objects in Python programs. Available methods include: __init__, apply_style, clear, clear_comment, clear_formula, clear_style, clear_value, get_comment, get_comment_size, get_style, has_comment, has_formula, and 8 additional methods. All public members are accessible to any Python application after installing the Aspose.Cells FOSS for Python package. Properties: comment, data_type, formula, style, value.

Properties

NameTypeAccessDescription
value``Read/WriteGets or sets the value of the cell.
formula``Read/WriteGets or sets the formula of the cell.
style``Read/WriteGets or sets the style of the cell.
comment``ReadGets the comment associated with the cell.
data_type``ReadGets the data type of the cell value.

Methods

SignatureDescription
__init__(value, formula)Initializes a new instance of the Cell class.
is_empty()Checks if the cell is empty.
clear_value()Clears the value of the cell (sets it to None).
clear_formula()Clears the formula of the cell (sets it to None).
clear()Clears both the value and formula of the cell.
set_comment(text, author, width, height)Sets a comment on the cell.
get_comment()Gets the comment from the cell.
clear_comment()Clears the comment from the cell.
has_comment()Checks if the cell has a comment.
set_comment_size(width, height)Sets the size of the comment box.
get_comment_size()Gets the size of the comment box.
apply_style(style)Applies a style to the cell.
get_style()Gets the style of the cell.
clear_style()Clears the style of the cell (resets to default).
has_formula()Checks if the cell has a formula.
is_numeric_value()Checks if the cell value is numeric.
is_text_value()Checks if the cell value is text.
is_boolean_value()Checks if the cell value is boolean.
is_date_time_value()Checks if the cell value is a date/time.
put_value(value)Sets the value of the cell.

Examples

from aspose.cells_foss import Workbook

workbook = Workbook()
worksheet = workbook.worksheets[0]
worksheet.cells["A1"].value = "Hello"
worksheet.cells["B1"].formula = "=A1"
from aspose.cells_foss import Workbook

workbook = Workbook()
worksheet = workbook.worksheets[0]
cell = worksheet.cells["A1"]
from aspose.cells_foss import Workbook

# Create a new workbook and access the first worksheet
workbook = Workbook()
worksheet = workbook.worksheets[0]

# Set a cell value using property assignment
cell_a1 = worksheet.cells["A1"]
cell_a1.value = "Hello World"

# Set a formula using property assignment
cell_b1 = worksheet.cells["B1"]
cell_b1.formula = "=LEN(A1)"

# Read cell properties using the property (no parentheses)
value = cell_a1.value
formula = cell_b1.formula

print(f"Value: {value}")
print(f"Formula: {formula}")

# Modify style via get_style / apply_style
style = cell_a1.get_style()
style.font.bold = True
style.font.size = 14
cell_a1.apply_style(style)

workbook.save("output.xlsx")

See Also

 English