2
votes

I am trying to create Excel File and appending data to it from a webpage. Excel file is created corrected and data is also saved in it, but when I try to load the file again and append data to it. it gives a Fatal error

Uncaught exception 'PHPExcel_Writer_Exception' with message 'File zip:///home/timespk/public_html/htmlParser/index.xlsx#xl/media/b1b39dadf76812b4c58e06ea6ddf57841.png does not exist' in /home/timespk/public_html/Classes/PHPExcel/Writer/Excel2007/ContentTypes.php:216 Stack trace: #0 /home/timespk/public_html/Classes/PHPExcel/Writer/Excel2007/ContentTypes.php(164): PHPExcel_Writer_Excel2007_ContentTypes->_getImageMimeType('zip:///home/tim...')

1 /home/timespk/public_html/Classes/PHPExcel/Writer/Excel2007.php(224):

PHPExcel_Writer_Excel2007_ContentTypes->writeContentTypes(Object(PHPExcel), false) #2 /home/timespk/public_html/htmlParser/index.php(216): PHPExcel_Writer_Excel2007->save('/home/timespk/p...') #3 {main} thrown in /home/timespk/public_html/Classes/PHPExcel/Writer/Excel2007/ContentTypes.php on line 216

Can anyone tell what I am doing wrong here?

2
Take a look at this line, Uncaught exception 'PHPExcel_Writer_Exception' with message 'File zip:///home/timespk/public_html/htmlParser/index.xlsx#xl/media/b1b39dadf76812b4c58e06ea6ddf57841.png does not exist', the picture doesn't exist ! - jbrtrnd
Thats not the issue, I am extracting jpeg files from a webpage, On first attempting to save the file the image is saved to excel file, but when I try to append the file, I have to load it and then its giving this error - Ali Maisam
Can you show the code that you are using initially to extract the image and save it to the file - Mark Baker

2 Answers

1
votes

This is the code that I am using to save Image to Excel file

$objPHPExcel2->getActiveSheet()->getColumnDimension('A')->setWidth(22);
$image = file_get_contents($imgSrc);
file_put_contents('image' . $highestRow . '.jpg', $image);
$gdImage = imagecreatefromjpeg('image' . $highestRow . '.jpg');
$objDrawing = new PHPExcel_Worksheet_MemoryDrawing();
$objDrawing->setImageResource($gdImage);
$objDrawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG);
$objDrawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT);
$objDrawing->setHeight(150);
$objDrawing->setCoordinates('A'. $highestRow);
$objDrawing->setWorksheet($objPHPExcel2->getActiveSheet());
0
votes

I believe that I've found proper solution to this problem which works with PHPExcel_Worksheet_Drawing: https://stackoverflow.com/a/23951597/925196