0

Tried to export an excel file through a Laravel blade but the issue exists when trying to add an image that is from external link not the same server (it's from google storage) the image is accessible through browser

The error is:

PhpOffice\PhpSpreadsheet\Writer\Exception File URL does not exist

Also, tried to get base64 and also didn't work

        $type = pathinfo($url, PATHINFO_EXTENSION);
        $data = file_get_contents($url);
        $base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);

        didn't work <img src='{{$url}}' style="height: 20px;" height="100px">
        didn't work <img src='{{$base64}}' style="height: 20px;" height="100px">
  • 3
    https://stackoverflow.com/questions/54786609/phpspreadsheet-how-do-i-place-a-image-from-link-into-my-excel-file – Sanya H Nov 18 '21 at 15:00

2 Answers2

1

I solved it by temporally download the image into the server and use the path to the image on the server.

  • I am managing to get the drawing to work when exporting to PDF but not when exporting to excel. Any idea why? – Luke Galea May 02 '22 at 12:20
0

Well, I think you should not use the full url instead, you may use the path to the image file. supose your image file url is example.com/assets/images/my-image.jpg, then you should use assets/images/my-image.jpg for example this is how I did it in my blade view using laravel excel:

  <td>
       <img width="70" src="assets/images/my-image.jpg" alt="">
  </td>

In fact, I just mentioned the relative path without the full url and it wored like a charm.

Codeparl
  • 300
  • 1
  • 8