1

I am generating an excel report where there is a column for passport size images. I want to add the images to that column one by one as per the record fetch.

My code for adding the image to the sheet is this:

                    $columnID = getExcelColumnValue($dataColumn);
                    //$objPHPExcel->getActiveSheet()->getStyle($columnID . $dataRow)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                    $objDrawing = new PHPExcel_Worksheet_Drawing();
                    $objDrawing->setPath(BASE_URL.$value);
                    $objDrawing->setCoordinates($columnID . $dataRow);
                    $objDrawing->setHeight(36);
                    $objDrawing->setWorksheet($objPHPExcel->getActiveSheet());

the error is this:

Fatal error: Uncaught exception 'PHPExcel_Exception' with message 'File http://128.199.210.59/data_collection/v2/images/formData/554dfdb0252e89781b90416a/1431176847206615.jpg not found!' in /var/www/data_collection/v2/php/api/PHPExcel/Classes/PHPExcel/Worksheet/Drawing.php:114 Stack trace: #0 /var/www/data_collection/v2/php/processing/formDashboard/exportToExcel.php(110): PHPExcel_Worksheet_Drawing->setPath('http://128.199....') #1 {main} thrown in /var/www/data_collection/v2/php/api/PHPExcel/Classes/PHPExcel/Worksheet/Drawing.php on line 114 

The image file is present at the destination, still it shows the error...

  • File needs to be on the __local__ file system, not a remote URL – Mark Baker May 10 '15 at 08:46
  • then what to do if that file resides on server inside the project's image folder??? –  May 12 '15 at 10:29
  • You provide a __filesystem__ path to the image. When the file is saved, it embeds the image itself inside the file so that it can be displayed whether the user is online or not – Mark Baker May 12 '15 at 10:32
  • no. i am not getting you. how can i add the image to excel file when user downloads the data in excel report format where the file is on server & not on local PC. –  May 13 '15 at 13:26
  • You tell PHPExcel to use an image via `$objDrawing->setPath();` by passing an absolute filesystem path to the image file. When PHPExcel saves the file, it takes that image file and embeds it directly in the xls/xlsx file that you create with the save.... that's a copy of the image itself, not of a url or a filesystem reference.... it's the actual binary content of the image file – Mark Baker May 13 '15 at 14:08
  • When the user views the Excel file in MS Excel, they're looking at the copy of the image that is stored in the xls/xlsx file itself, not at some remote web url that may or may not exist, or where (if an image does exist) it may or may not be the same as the one they expect to see – Mark Baker May 13 '15 at 14:08
  • ok. then how do i add the image file to excel sheet. what is the alternative way to do that?? –  May 16 '15 at 07:38
  • You do exactly what I said: the file must be on the server where you're executing the script, and you must provide a local filesystem reference to the image file, not a URL – Mark Baker May 16 '15 at 08:17
  • I'm guessing in your case that the filesystem reference would be `/var/www/data_collection/v2/images/formData/554dfdb0252e89781b90416a/1431176847206615.jpg` – Mark Baker May 16 '15 at 08:20
  • that means instead of url like https://www.example.com/data_collection/v2/images/formData/554dfdb0252e89781b90416a/1431176847‌​206615.jpg that i am using currently, i have to provide the above address you typed?? –  May 20 '15 at 05:18

0 Answers0