Add an image into a PHPExcel cell

Add an image into a PHPExcel cell 

The following assumes a dataobject ($obj) with a has_one Image (called image) and adds that to a cell in phpexcell worksheet

$oCell->setValue('');
if ($obj->ImageID && file_exists($obj->Image()->getFullPath())) {
	$objDrawing = new PHPExcel_Worksheet_Drawing();
	$objDrawing->setName('PHPExcel image');
	$objDrawing->setDescription('PHPExcel image');
	$objDrawing->setPath($obj->Image()->getFullPath());
	$objDrawing->setHeight(100);
	$objDrawing->setCoordinates($oCell->getCoordinate());
	$objDrawing->setOffsetX(100);
	$objDrawing->setWorksheet($oSheet);
}
Rate this post (8 rating(s))