list($width, $height, $type, $attr) = getimagesize($img_path); if( $width>100 || $height >100 ){ if($width > $height){ $height = $height/($width/100); $width = 100; }else{ $width = $width/($height/100); $height = 100; } } $img = new PHPExcel_Worksheet_Drawing(); $img->setPath($img_path);//写入图片路径 if($height<100){ $offsetY = (100-$height)/2; $img->setOffsetY($offsetY); } if($width<100){ $offsetX = (100-$width)/2; $img->setOffsetX($offsetX); } $img->setWidthAndHeight($width,$height); $img->setCoordinates($column.$row);//设置图片所在表格位置 $img->setWorksheet($objActSheet);//把图片写到当前的表格中 $objActSheet->getRowDimension($row)->setRowHeight(90);
记得固定列宽未14.5