本例是在Laravel里面使用了use Excel;
1、此方法适用于项目文件夹下的图片
$img = "213123.png";
$objDrawing = new \PHPExcel_Worksheet_Drawing();
$objDrawing->setName('ZealImg');
$objDrawing->setDescription('Image inserted by Zeal');
$objDrawing->setPath($img);
$objDrawing->setHeight(250);
$objDrawing->setWidth(250);
$objDrawing->setCoordinates('A2');//单元格
$objDrawing->setOffsetX(20);//偏移量
$objDrawing->setOffsetY(20);
$objDrawing->setRotation(15);
$objDrawing->getShadow()->setVisible(true);
$objDrawing->getShadow()->setDirection(36);
$objDrawing->setWorksheet($sheet);//$sheet为当前工作表
2、此方法适用网络图片,通过GD创建画布的方式实现
$img = 'http://www.xxx.com/image/1.png';
$img = $this->imagecreatefrompng($img);
$width = imagesx($img);
$height = imagesy($img);
$sheet->setSize($cell,$width/5,$height);//设置单元格 宽高
$objDrawing = new \PHPExcel_Worksheet_MemoryDrawing();
$objDrawing->setName('Sample image');
$objDrawing->setDescription('Sample image');
$objDrawing->setCoordinates($cell);
$objDrawing->setImageResource($img);
$objDrawing->setOffsetX(10);
$objDrawing->setOffsetY(10);
$objDrawing->setRenderingFunction(\PHPExcel_Worksheet_MemoryDrawing::RENDERING_DEFAULT);//渲染方法
$objDrawing->setMimeType(\PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT);
$objDrawing->setHeight($height);
$objDrawing->setWorksheet($sheet);//同上