?phpini_set(display_errors,1);ini_set('include_path', ini_get('include_path').';f://sources//phpexcel_1.7.8-with_documentation-msoffice_format//classes//');//设置此页面包含路径include 'phpexcel.php';include 'phpexcel/iofactory.php';defin
load($filename);$worksheet = $phpexcel->getactivesheet();$imageinfo = extractimagefromworksheet($worksheet,f://);print_r($imageinfo);function getextendfilename($file_name) { $extend = pathinfo($file_name); $extend = strtolower($extend[extension]); return $extend;}function extractimagefromworksheet($worksheet,$basepath){ $result = array(); $imagefilename = ; foreach ($worksheet->getdrawingcollection() as $drawing) { $xy=$drawing->getcoordinates(); $path = $basepath; // for xlsx if ($drawing instanceof phpexcel_worksheet_drawing) { $filename = $drawing->getpath(); $imagefilename = $drawing->getindexedfilename(); $path = $path . $drawing->getindexedfilename(); copy($filename, $path); $result[$xy] = $path; // for xls } else if ($drawing instanceof phpexcel_worksheet_memorydrawing) { $image = $drawing->getimageresource(); $renderingfunction = $drawing->getrenderingfunction(); switch ($renderingfunction) { case phpexcel_worksheet_memorydrawing::rendering_jpeg: $imagefilename = $drawing->getindexedfilename(); $path = $path . $drawing->getindexedfilename(); imagejpeg($image, $path); break; case phpexcel_worksheet_memorydrawing::rendering_gif: $imagefilename = $drawing->getindexedfilename(); $path = $path . $drawing->getindexedfilename(); imagegif($image, $path); break; case phpexcel_worksheet_memorydrawing::rendering_png: $imagefilename = $drawing->getindexedfilename(); $path = $path . $drawing->getindexedfilename(); imagegif($image, $path); break; case phpexcel_worksheet_memorydrawing::rendering_default: $imagefilename = $drawing->getindexedfilename(); $path = $path . $drawing->getindexedfilename(); imagegif($image, $path); break; } $result[$xy] = $imagefilename; } } return $result;}
原文地址:利用phpexcel读取excel中文件, 感谢原作者分享。