PHPOffice/PhpSpreadsheet · error · SpreadsheetException
Item is not a drawing
Error message
Item is not a drawing
What it means
DataType::TYPE_DRAWING_IN_CELL ('drawingCell') is the one datatype whose value must be a BaseDrawing instance (Drawing, MemoryDrawing). setValueExplicit() checks instanceof BaseDrawing and throws for anything else, because in-cell drawings store the drawing object itself, not a path or string.
Source
Thrown at src/PhpSpreadsheet/Cell/Cell.php:352
break;
case DataType::TYPE_FORMULA:
$this->value = StringHelper::convertToString($value, true);
break;
case DataType::TYPE_BOOL:
$this->value = (bool) $value;
break;
case DataType::TYPE_ISO_DATE:
$this->value = SharedDate::convertIsoDate($value);
$dataType = DataType::TYPE_NUMERIC;
break;
case DataType::TYPE_DRAWING_IN_CELL:
if ($value instanceof BaseDrawing) {
$this->value = $value;
} else {
throw new SpreadsheetException('Item is not a drawing');
}
break;
case DataType::TYPE_ERROR:
$this->value = DataType::checkErrorCode($value);
break;
default:
throw new SpreadsheetException('Invalid datatype: ' . $dataType);
}
// set the datatype
$this->dataType = $dataType;
$this->updateInCollection();
$cellCoordinate = $this->getCoordinate();
self::updateIfCellIsTableHeader($this->getParent()?->getParent(), $this, $oldValue, $value);
$worksheet = $this->getWorksheet();View on GitHub (pinned to 65b080eef4)
Solutions
- Construct and pass a BaseDrawing instance: $drawing = new Drawing(); $drawing->setPath('logo.png'); then setValueExplicit($drawing, DataType::TYPE_DRAWING_IN_CELL)
- Or use the classic drawing API instead: $drawing->setWorksheet($sheet); $drawing->setCoordinates('A1')
Example fix
// before
$cell->setValueExplicit('images/logo.png', DataType::TYPE_DRAWING_IN_CELL); // throws
// after
$drawing = new Drawing();
$drawing->setPath('images/logo.png');
$cell->setValueExplicit($drawing, DataType::TYPE_DRAWING_IN_CELL); Defensive patterns
Strategy: type-guard
Validate before calling
if ($drawingOrPath instanceof BaseDrawing) {
$cell->setValueExplicit($drawingOrPath, DataType::TYPE_DRAWING_IN_CELL);
} else {
$drawing = new Drawing();
$drawing->setPath((string) $drawingOrPath);
$cell->setValueExplicit($drawing, DataType::TYPE_DRAWING_IN_CELL);
} Type guard
function isAcceptableDrawingValue(mixed $value): bool
{
return $value instanceof BaseDrawing;
} Try / catch
null
Prevention
- TYPE_DRAWING_IN_CELL accepts only Drawing/MemoryDrawing objects - never paths or strings
- Type-hint drawing parameters in your own wrappers as BaseDrawing to fail at the boundary
- Use the classic API ($drawing->setWorksheet/setCoordinates) when you only have a file path
When it happens
Trigger: setValueExplicit('logo.png', DataType::TYPE_DRAWING_IN_CELL) or passing a URL/array/resource instead of a Drawing object; code that assumes the drawing type takes a file path string.
Common situations: Adopting the in-cell drawing feature and guessing the API from the constant name; porting code that used external drawings (where you set a path) to the in-cell variant.
Related errors
AI-assisted analysis of PHPOffice/PhpSpreadsheet@65b080eef4 (2026-08-17).
Data as JSON: /api/errors/b0148f13f50536fd.
Report an issue: GitHub.