鍍金池/ 問(wèn)答/PHP  HTML/ PHPExcel導(dǎo)出遠(yuǎn)程圖片有實(shí)現(xiàn)方法嗎?

PHPExcel導(dǎo)出遠(yuǎn)程圖片有實(shí)現(xiàn)方法嗎?

調(diào)用其它接口生成二維碼圖片,綜合本地服務(wù)器Excel表格導(dǎo)出

回答
編輯回答
孤酒

不懂你的問(wèn)題所在.

是要把二維碼圖片添加到excel文件中?
如果是這樣, 那和普通文件沒(méi)差別, 直接給excel圖片加文件就是了.
如果PHPExcel的參數(shù)是圖片地址, 那保存成臨時(shí)文件就成, 如果是資源, 用php://temp來(lái)新建個(gè)$fp就成.

2018年6月20日 12:59
編輯回答
熟稔

先循環(huán)將遠(yuǎn)程圖片下載到服務(wù)器,在將圖片寫(xiě)入excel 最后將下載的圖片unlink

2017年3月26日 23:12
編輯回答
忠妾
遠(yuǎn)程圖片下載的本地臨時(shí)目錄
$temp_pic = $this->download(你的遠(yuǎn)程圖片鏈接,'./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);//寫(xiě)入圖片路徑
    $img->setHeight(100);//寫(xiě)入圖片高度
    $img->setWidth(100);//寫(xiě)入圖片寬度
    $img->setOffsetX(105);//寫(xiě)入圖片在指定格中的X坐標(biāo)值
    $img->setOffsetY(5);//寫(xiě)入圖片在指定格中的Y坐標(biāo)值
    $img->setRotation(1);//設(shè)置旋轉(zhuǎn)角度
    $img->getShadow()->setVisible(true);
    $img->getShadow()->setDirection(50);
    $img->setCoordinates('C1');//設(shè)置圖片所在表格位置
    $img->setWorksheet($objPHPExcel->getActiveSheet());//把圖片寫(xiě)到當(dāng)前的表格中
}

    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); // 信任任何證書(shū)
        $file = curl_exec($ch);
        curl_close($ch);
        $filename = pathinfo($url, PATHINFO_BASENAME);
        $resource = fopen($path . $filename, 'a');
        fwrite($resource, $file);
        fclose($resource);
        return $filename;
    }

不知道你是不是要這個(gè)

2018年2月10日 18:36