Getting image in PHPExcel


I want to read / get an image from an excel file in PHP using PHPExcel. This code is used to retrieve a value from a specific cell.

    $objPHPExcel->getActiveSheet()->getCell('B5')->getValue();

This only returns the value of the cell, but I cannot get the image. Is there any way to do this?

+5
source share
2 answers

Googlingphpexcel read image provided this page as a second result. He tells you how to do it.

To directly indicate relevant information:

$objPHPExcel->getActiveSheet()->getDrawingCollection()will return an ArrayObject of all image objects on the active sheet.

PHPExcel_Worksheet_Drawing, PHPExcel_Worksheet_MemoryDrawing: , is_a(). , ( API), ( PHPExcel_Worksheet_Drawing), PHPExcel_Worksheet_MemoryDrawing. getName() getDescription() .

, , :

$objPHPExcel->getActiveSheet()->getHeaderFooter()->getImages() / . PHPExcel_Worksheet_HeaderFooterDrawing. PHPExcel_Worksheet_Drawing .

+7

. .

$objPHPExcel = PHPExcel_IOFactory::load($_FILES['archivo']['tmp_name']);

$i = 0;
foreach ($objPHPExcel->getActiveSheet()->getDrawingCollection() as $drawing) {
    if ($drawing instanceof PHPExcel_Worksheet_MemoryDrawing) {
        ob_start();
        call_user_func(
            $drawing->getRenderingFunction(),
            $drawing->getImageResource()
        );

        $imageContents = ob_get_contents();
        ob_end_clean();
        $extension = 'png';
    } else {
        $zipReader = fopen($drawing->getPath(),'r');
        $imageContents = '';

        while (!feof($zipReader)) {
            $imageContents .= fread($zipReader,1024);
        }
        fclose($zipReader);
        $extension = $drawing->getExtension();
    }
    $myFileName = '00_Image_'.++$i.'.'.$extension;
    file_put_contents($myFileName,$imageContents);
}

: http://phpexcel.codeplex.com/workitem/18189

+5

All Articles