Add images to a excel file using PHP

Roch picture Roch · Feb 7, 2013 · Viewed 23.5k times · Source

I'm using the following function to add content to an excel file using PHP :

function __writeString($row, $col, $value ) {
        $L = strlen($value);
        $this->file .= pack("ssssss", 0x204, 8 + $L, $row, $col, 0x0, $L);
        $this->file .= $value;
}

I would like to know how I can add images in my cells the same way, by supplying its url as a value for instance.

Answer

trigun0x2 picture trigun0x2 · Feb 7, 2013

Take a look at this: PHPExcel. It will provide you will all the tools you need to read and write Excel from PHP.

Once you have PHPExcel installed, you can use something like this to insert:

$objDrawing = new PHPExcel_Worksheet_Drawing();

$objDrawing->setPath('./images/picture.png');

$objDrawing->setCoordinates('A11');