Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fetch the images present in the excel cell?

I need to read the images present in the cell, I know how to read the drawing present the sheet but the getDrawingCollection() only works on sheet. is there any function that will give the images present in the cell while getting the data. The below code is used to fetch the data of the sheet.

$spreadsheet = IOFactory::load($inputFileName);
  $worksheet = $spreadsheet->setActiveSheetIndex(2);
  foreach ($worksheet->getRowIterator() as $row) {      
      $cellIterator = $row->getCellIterator();
      $cellIterator->setIterateOnlyExistingCells(FALSE); 
      foreach ($cellIterator as $cell) {
          echo $cell->getValue();
      }          
  }

If the question is duplicate I am happy to remove it.

like image 767
Bhagchandani Avatar asked Oct 26 '25 04:10

Bhagchandani


1 Answers

I don't think it has any function for that, but you can do something like this:

foreach ($worksheet->getDrawingCollection() as $drawing) {
    $drawings[$drawing->getCoordinates()] = $drawing;
}
// then find your image using your cell coordinates
$image = $drawings[$cell->getCoordinates()];

// or
foreach ($worksheet->getDrawingCollection() as $drawing) {
    if($drawing->getCoordinates() == $cell->getCoordinates()){
        // or do your stuff here
    }
}
like image 92
FarhadK2 Avatar answered Oct 28 '25 18:10

FarhadK2



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!