phpexcel导出excel等比例缩放图片

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

posted on 2018-03-10 12:40  会学习的猪  阅读(537)  评论(0编辑  收藏  举报

导航