我正在使用PHPExcel来解析我的excel文件。我的文件在每一行都有图像。我使用“getDrawingCollection”函数来获取excel文件中的所有图像。它整体工作得很好。但是getDrawingCollection函数无法识别某些图像。我需要更改代码中的任何内容吗?
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objPHPExcel = $objReader->load($uploadfile);
$objWorksheet = $objPHPExcel->getActiveSheet();
foreach ($objWorksheet->getDrawingCollection() as $drawing) {
$string = $drawing->getCoordinates();
$coordinate = PHPExcel_Cell::coordinateFromString($string);
if ($drawing instanceof PHPExcel_Worksheet_Drawing) {
//copy image
}
}
答案 0 :(得分:0)
if ($drawing instanceof PHPExcel_Worksheet_Drawing) {
不会拿起“记忆图纸”
您可能想要使用
if ($drawing instanceof PHPExcel_Worksheet_BaseDrawing) {
代替;类似的东西:
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);
}