php生成excel带图片格式,PHPExcel导出远程图片有实现方法吗?

远程图片下载的本地临时目录

$temp_pic = $this->download(你的远程图片链接,'./Public/temp/export/');

$local_pic_path = './Public/excel/temp/export/'.$temp_pic;

if (file_exists($local_pic_path)) {

$img = new \PHPExcel_Worksheet_Drawing();

$img->setPath($local_pic_path);//写入图片路径

$img->setHeight(100);//写入图片高度

$img->setWidth(100);//写入图片宽度

$img->setOffsetX(105);//写入图片在指定格中的X坐标值

$img->setOffsetY(5);//写入图片在指定格中的Y坐标值

$img->setRotation(1);//设置旋转角度

$img->getShadow()->setVisible(true);

$img->getShadow()->setDirection(50);

$img->setCoordinates('C1');//设置图片所在表格位置

$img->setWorksheet($objPHPExcel->getActiveSheet());//把图片写到当前的表格中

}

private function download($url, $path = 'images/')

{

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 信任任何证书

$file = curl_exec($ch);

curl_close($ch);

$filename = pathinfo($url, PATHINFO_BASENAME);

$resource = fopen($path . $filename, 'a');

fwrite($resource, $file);

fclose($resource);

return $filename;

}

不知道你是不是要这个

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值