Cell class represents a single cell within a worksheet. It manages the cell’s value, data type, formula, style, and various properties.
Class Overview
Namespace:PhpOffice\PhpSpreadsheet\Cell
Source: src/PhpSpreadsheet/Cell/Cell.php
A Cell object contains a value, knows its coordinate, data type, and provides access to formatting and calculation features.
Constructor
__construct(mixed $value, ?string $dataType, Worksheet $worksheet)
Create a new cell.
Initial value for the cell
Data type (see DataType::TYPE_*), or null for automatic detection
Parent worksheet
Cells are typically created through worksheet methods like
getCell() or setCellValue() rather than instantiated directly.Getting Cell Information
getCoordinate()
Get the cell coordinate.
Cell coordinate (e.g., ‘A1’, ‘B5’)
getColumn()
Get the cell column.
Column letter (e.g., ‘A’, ‘B’, ‘AA’)
getRow()
Get the cell row number.
Row number (1-based)
getWorksheet()
Get the parent worksheet.
The worksheet containing this cell
Value Operations
getValue()
Get the cell value.
The raw cell value
getValueString()
Get the cell value as a string.
String representation of the value
setValue(mixed $value, ?IValueBinder $binder = null)
Set the cell value.
Value to set (string, number, DateTime, bool, etc.)
Optional custom value binder
The cell object for method chaining
setValueExplicit(mixed $value, string $dataType = DataType::TYPE_STRING)
Set the cell value with an explicit data type.
Value to set
Explicit data type constant
The cell object for method chaining
Available Data Types
Data Type
getDataType()
Get the cell data type.
Data type constant (DataType::TYPE_*)
setDataType(string $dataType)
Set the cell data type.
Data type constant
The cell object
isFormula()
Check if the cell contains a formula.
True if cell contains a formula
Calculated Values
getCalculatedValue(bool $resetLog = true)
Get the calculated cell value (evaluates formulas).
Whether to reset the calculation log
The calculated value
getCalculatedValueString()
Get the calculated value as a string.
String representation of calculated value
getOldCalculatedValue()
Get the cached calculated value from the file.
Cached calculated value
setCalculatedValue(mixed $originalValue, bool $tryNumeric = true)
Set the old calculated value (cached).
Cached calculated value
Try to convert to numeric
Formatted Value
getFormattedValue()
Get the cell value with number formatting applied.
Formatted value string
Styling
getStyle()
Get the cell’s style object.
Style object for this cell
getAppliedStyle()
Get the applied style (including conditional formatting).
Effective style object
Hyperlinks
hasHyperlink()
Check if the cell has a hyperlink.
True if cell has a hyperlink
getHyperlink()
Get the cell’s hyperlink.
Hyperlink object
setHyperlink(?Hyperlink $hyperlink = null)
Set a hyperlink for the cell.
Hyperlink object, or null to remove
The cell object
Data Validation
hasDataValidation()
Check if the cell has data validation.
True if cell has validation rules
getDataValidation()
Get the cell’s data validation object.
Data validation object
setDataValidation(?DataValidation $dataValidation = null)
Set data validation for the cell.
Data validation object, or null to remove
hasValidValue()
Check if the cell’s value is valid according to its validation rules.
True if value is valid
Merge Ranges
isInMergeRange()
Check if the cell is part of a merged range.
True if cell is in a merge range
isMergeRangeValueCell()
Check if this is the master cell (top-left) of a merged range.
True if this is the value cell
getMergeRange()
Get the merge range that this cell belongs to.
Range string (e.g., ‘A1:C3’), or false if not merged
Range Checking
isInRange(string $range)
Check if the cell is within a specified range.
Range to check (e.g., ‘A1:D10’)
True if cell is in the range
Complete Example
Related Classes
- Worksheet - Parent worksheet containing the cell
- Spreadsheet - Parent workbook
DataType- Cell data type constantsDataValidation- Cell data validation rulesHyperlink- Cell hyperlinkStyle- Cell formatting and style

