在PHPExcel中检索图像 [英] Retrieving image in PHPExcel

查看:70
本文介绍了在PHPExcel中检索图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想使用PHPExcel从Excel文件读取/检索图像到PHP. 该代码用于从特定单元格中检索值.


I want to read/retrieve an Image from excel file to PHP using PHPExcel. This code is used to retrieve a value from a particular cell.

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

这仅检索单元格值,但是我无法检索图像.有办法吗?

This retrieves only the cell value, But i cant retrieve a image. Is there a way to do that?

推荐答案

谷歌搜索phpexcel read image 产生此页面作为第二个结果.它告诉您如何执行此操作.

Googling phpexcel read image yielded this page as the second result. It tells you how to do this.

要直接引用相关信息:

$objPHPExcel->getActiveSheet()->getDrawingCollection() 将返回活动工作表中所有图像对象的ArrayObject.

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

这些对象将是PHPExcel_Worksheet_DrawingPHPExcel_Worksheet_MemoryDrawing对象:您可以使用识别哪些对象is_a() .然后,您可以使用适合该类的方法(如API中所述)从文件(对于PHPExcel_Worksheet_Drawing对象)或直接从PHPExcel_Worksheet_MemoryDrawing对象本身读取图像数据. getName()getDescription()方法可用于从图像对象检索相关值.

These objects will be either PHPExcel_Worksheet_Drawing or PHPExcel_Worksheet_MemoryDrawing objects: you can identify which using is_a(). You can then use the methods appropriate to that class (as described in the API) either to read the image data from file (for PHPExcel_Worksheet_Drawing objects) or directly from the PHPExcel_Worksheet_MemoryDrawing object itself. The getName() and getDescription() methods can be used to retrieve the relevant values from the image object.

请注意,还可以将图像对象与打印头相关联:

Note that it's also possible to have image objects associated with print headers:

$objPHPExcel->getActiveSheet()->getHeaderFooter()->getImages()可用于从页眉/页脚检索图像.这是PHPExcel_Worksheet_HeaderFooterDrawing对象的数组.所有PHPExcel_Worksheet_Drawing方法都可用于从这些对象中提取图像文件.

$objPHPExcel->getActiveSheet()->getHeaderFooter()->getImages() can be used to retrieve images from the header/footer. This is an array of PHPExcel_Worksheet_HeaderFooterDrawing objects. All the PHPExcel_Worksheet_Drawing methods can be used to extract the image file from these objects.

这篇关于在PHPExcel中检索图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆