phpexcel - Extracting images from an Excel file (xlsx) using PHP -


how can read images excel file using phpexcel , save images in server , display them? extension of file .xlsx.

my code:

$objphpexcel = phpexcel_iofactory::load($path);  foreach ($objphpexcel->getactivesheet()->getdrawingcollection() $drawing) {     if ($drawing instanceof phpexcel_worksheet_memorydrawing) {         ob_start();         call_user_func(             $drawing->getrenderingfunction(),             $drawing->getimageresource()         );         $imagecontents = ob_get_contents();          ob_end_clean();     }  } 

thanks!!

$objphpexcel->getactivesheet()->getdrawingcollection() 

will return arrayobject of image objects in active worksheet.

these objects either phpexcel_worksheet_drawing or phpexcel_worksheet_memorydrawing objects: can identify using [is_a()][1]. can use methods appropriate class (as described in api) either read image data file (for phpexcel_worksheet_drawing objects) or directly phpexcel_worksheet_memorydrawing object itself. getname() , getdescription() methods can used retrieve relevant values fro image object.

note it's possible have image objects associated print headers:

$objphpexcel->getactivesheet()->getheaderfooter()->getimages() 

can used retrieve images header/footer. array of phpexcel_worksheet_headerfooterdrawing objects. phpexcel_worksheet_drawing methods can used extract image file these objects.

edit

spoonfeeding time.

this extract images active worksheet, , write them files on server.

$objphpexcel = phpexcel_iofactory::load($path);  $i = 0; foreach ($objphpexcel->getactivesheet()->getdrawingcollection() $drawing) {     if ($drawing instanceof phpexcel_worksheet_memorydrawing) {         ob_start();         call_user_func(             $drawing->getrenderingfunction(),             $drawing->getimageresource()         );         $imagecontents = ob_get_contents();         ob_end_clean();         switch ($drawing->getmimetype()) {             case phpexcel_worksheet_memorydrawing::mimetype_png :                     $extension = 'png'; break;             case phpexcel_worksheet_memorydrawing::mimetype_gif:                     $extension = 'gif'; break;             case phpexcel_worksheet_memorydrawing::mimetype_jpeg :                     $extension = 'jpg'; break;         }     } 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); } 

files named

00_image_n.extension 

where n number starting 1, , extension appropriate extension (png,jpg,gif, whatever) image type.


Comments

Popular posts from this blog

How do you change vbulletin's home page to the forums instead of the default (CMS or Activity Stream)? -

c++ - Troubles when compiling phash program -