Insert image from Url

Topics: Developer Forum
Jul 23, 2013 at 12:16 PM

I am trying to create an excel file containing some reports and i have a column called "Image Thumbs" for our picture check-ins. I need to add those images in each cell in order to be anchored and be fixed on cell when applying some filters or sorting etc.

The main problem is that for PHPExcel_Worksheet_Drawing i got an error when trying to setPath for my images.

Is there a way to add images on excel from url ? Our images are on amazon s3 bucket.
Jul 23, 2013 at 12:50 PM
You need a filesystem file, not a URL.
Jul 23, 2013 at 2:34 PM
This cannot be done via URL ? Only from filesystem images ?

Eitherway, is there a way in PHPExcel to anchor a photo to cell ? If i apply some filters and sortings on table, also images to move with rows.
Jul 23, 2013 at 4:37 PM
Images in Excel are overlaid on the worksheet: either linked over a single (top-left) cell, with a height and width; or to two cells (top-left and bottom-right). In most cases with PHPExcel, we use the single anchor method
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName('PHPExcel logo');
$objDrawing->setDescription('PHPExcel logo');
$objDrawing->setPath('./images/phpexcel_logo.gif');       // filesystem reference for the image file
$objDrawing->setHeight(36);                 // sets the image height to 36px (overriding the actual image height); 
$objDrawing->setCoordinates('D24');    // pins the top-left corner of the image to cell D24
$objDrawing->setOffsetX(10);                // pins the top left corner of the image at an offset of 10 points horizontally to the right of the top-left corner of the cell
Jul 24, 2013 at 9:25 AM

Thanks a lot for your response. This work well and it fits to cell after i set rowHeight and ColumnWidth dimensions.

One small problem i have with images that are too long, let's say 50w and 500h or 50h and 500w. It works if i set height at 50 and on images that have a long width it still get out of cell borders. It won't work if i add setHeight and setWidth both togheter.

Kind Regards,

Andrei Kun
Oct 2, 2013 at 10:30 PM

Could you help me?
I want to use a path which is in a variable $image, the problem is that it is not working, it works just when I type the path manually.
this is my script, I hope one of you can help me.
while($fields = mysql_fetch_array($query)){
    $image = $fields['bar_code'];
    $objDrawing = new PHPExcel_Worksheet_Drawing();
Oct 3, 2013 at 12:23 PM
Do you have a 'File xxxx not found!' exception when you use a variable?
If Yes, check the path, use realpath() to solve the '..' and recheck.
Oct 5, 2013 at 12:35 AM
Hi, thanks,
The issue was that there were some files wich didn´t exists and what I did was to use if(file_exist()) as follows:
        $objDrawing = new PHPExcel_Worksheet_Drawing();
        $objDrawing->setDescription('Reporte de Pedidos');