Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PhpSpreadsheet can't retrieve images placed inside cell #4014

Closed
AntonioA-D-C opened this issue May 2, 2024 · 2 comments
Closed

PhpSpreadsheet can't retrieve images placed inside cell #4014

AntonioA-D-C opened this issue May 2, 2024 · 2 comments

Comments

@AntonioA-D-C
Copy link

  
    $spreadsheet=  IOFactory::load($this->file);
    $i= 0;
    dd($spreadsheet->getActiveSheet($row)->getDrawingCollection());
    foreach ($spreadsheet->getActiveSheet()->getDrawingCollection() as $drawing) {
      if ($drawing instanceof MemoryDrawing) {
          ob_start();
          call_user_func(
              $drawing->getRenderingFunction(),
              $drawing->getImageResource()
          );
          $imageContents = ob_get_contents();
          ob_end_clean();
          switch ($drawing->getMimeType()) {
              case MemoryDrawing::MIMETYPE_PNG :
                  $extension = 'png';
                  break;
              case MemoryDrawing::MIMETYPE_GIF:
                  $extension = 'gif';
                  break;
              case 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 = time() .++$i. '.' . $extension;
      dd($myFileName);
    }

Here my script won't trigger when I have images that are inside cells, it ignores images inside the cells for images outside the cells, how to fix this or how to retrieve images contained within cells

@oleibman
Copy link
Collaborator

oleibman commented May 5, 2024

Confirming what you've already surmised. PhpSpreadsheet has no way to set a cell value to an image. As for retrieving such an image, I've looked at a spreadsheet which does this, and I really don't see how this is handled in the xml. Even if I do figure it out, it would probably be a pretty major change to extend the set of datatypes to which a cell value can be set.

@oleibman
Copy link
Collaborator

Closing as duplicate of #4034.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants