{"record":{"id":"b0148f13f50536fd","repo":"PHPOffice/PhpSpreadsheet","slug":"item-is-not-a-drawing","errorCode":null,"errorMessage":"Item is not a drawing","messagePattern":"Item is not a drawing","errorType":"exception","errorClass":"SpreadsheetException","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Cell/Cell.php","lineNumber":352,"sourceCode":"                break;\n            case DataType::TYPE_FORMULA:\n                $this->value = StringHelper::convertToString($value, true);\n\n                break;\n            case DataType::TYPE_BOOL:\n                $this->value = (bool) $value;\n\n                break;\n            case DataType::TYPE_ISO_DATE:\n                $this->value = SharedDate::convertIsoDate($value);\n                $dataType = DataType::TYPE_NUMERIC;\n\n                break;\n            case DataType::TYPE_DRAWING_IN_CELL:\n                if ($value instanceof BaseDrawing) {\n                    $this->value = $value;\n                } else {\n                    throw new SpreadsheetException('Item is not a drawing');\n                }\n\n                break;\n            case DataType::TYPE_ERROR:\n                $this->value = DataType::checkErrorCode($value);\n\n                break;\n            default:\n                throw new SpreadsheetException('Invalid datatype: ' . $dataType);\n        }\n\n        // set the datatype\n        $this->dataType = $dataType;\n\n        $this->updateInCollection();\n        $cellCoordinate = $this->getCoordinate();\n        self::updateIfCellIsTableHeader($this->getParent()?->getParent(), $this, $oldValue, $value);\n        $worksheet = $this->getWorksheet();","sourceCodeStart":334,"sourceCodeEnd":370,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Cell/Cell.php#L334-L370","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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')"],"exampleFix":"// before\n$cell->setValueExplicit('images/logo.png', DataType::TYPE_DRAWING_IN_CELL); // throws\n\n// after\n$drawing = new Drawing();\n$drawing->setPath('images/logo.png');\n$cell->setValueExplicit($drawing, DataType::TYPE_DRAWING_IN_CELL);","handlingStrategy":"type-guard","validationCode":"if ($drawingOrPath instanceof BaseDrawing) {\n    $cell->setValueExplicit($drawingOrPath, DataType::TYPE_DRAWING_IN_CELL);\n} else {\n    $drawing = new Drawing();\n    $drawing->setPath((string) $drawingOrPath);\n    $cell->setValueExplicit($drawing, DataType::TYPE_DRAWING_IN_CELL);\n}","typeGuard":"function isAcceptableDrawingValue(mixed $value): bool\n{\n    return $value instanceof BaseDrawing;\n}","tryCatchPattern":"null","preventionTips":["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"],"tags":["phpspreadsheet","drawing","datatype","type-mismatch","in-cell-drawing"],"backgroundTag":"type-mismatch","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}