komal Posted April 21, 2012 Share Posted April 21, 2012 Hello Everyone, I'm new to PHP and got a good big stuff. I would like to write an image in excel file. There will be almost 600+ rows and each row will have url and qrcode image. I would like to write an excel file which will write url and respective image into the next cell of the url. Is it possible to write an image in excel file? If yes, can anyone please guide me how? I have read so many post saying to use a pear package but again pear package is not allowing to write jpe/gif it only allows .bmp files. So, pear package is I don't think will work for me. I have also attached an example excel file which is showing the way I require to have an output. Please anyone if having any idea guide me and let me know. Thank you in advance for your help. Looking forward to hear from you soon! 18154_.zip Quote Link to comment https://forums.phpfreaks.com/topic/261361-write-image-in-excel-file-using-php/ Share on other sites More sharing options...
darkfreaks Posted April 22, 2012 Share Posted April 22, 2012 example using pears spreadsheet excel writer. <?php ini_set("include_path", get_include_path().":/home/myaccount/php"); ini_set("max_execution_time","30"); // not required unless you are hitting a limit ini_set("memory_limit","32M"); // not required unless you are hitting a limit require_once 'Spreadsheet/Excel/Writer.php'; $workbook = new Spreadsheet_Excel_Writer(); $workbook->setTempDir('/home/myaccount/tmp'); // Creating a worksheet $worksheet =& $workbook->addWorksheet('Test for Bitmap'); $worksheet->insertBitmap(0,0,'image.bmp'); //send the file $workbook->send('test.xls'); //close the workbook $workbook->close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/261361-write-image-in-excel-file-using-php/#findComment-1339465 Share on other sites More sharing options...
darkfreaks Posted April 22, 2012 Share Posted April 22, 2012 my bad sorry skipped the part where you said it only adds bitmaps and you are right have you tried PHPEXCEL library? example: $gdImage = imagecreatefromjpeg('images/officelogo.jpg'); // Add a drawing to the worksheetecho date('H:i:s') . " Add a drawing to the worksheet\n"; $objDrawing = new PHPExcel_Worksheet_MemoryDrawing(); $objDrawing->setName('Sample image');$objDrawing->setDescription('Sample image'); $objDrawing->setImageResource($gdImage); $objDrawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG); $objDrawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT); $objDrawing->setHeight(150); $objDrawing->setWorksheet($objPHPExcel->getActiveSheet()); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); Quote Link to comment https://forums.phpfreaks.com/topic/261361-write-image-in-excel-file-using-php/#findComment-1339468 Share on other sites More sharing options...
komal Posted April 23, 2012 Author Share Posted April 23, 2012 Hello darkfreaks, Thank you for youre help! Yes, this code works perfect!!! Thanks a lot. Thanks, Komal. my bad sorry skipped the part where you said it only adds bitmaps and you are right have you tried PHPEXCEL library? example: $gdImage = imagecreatefromjpeg('images/officelogo.jpg'); // Add a drawing to the worksheetecho date('H:i:s') . " Add a drawing to the worksheet\n"; $objDrawing = new PHPExcel_Worksheet_MemoryDrawing(); $objDrawing->setName('Sample image');$objDrawing->setDescription('Sample image'); $objDrawing->setImageResource($gdImage); $objDrawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG); $objDrawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT); $objDrawing->setHeight(150); $objDrawing->setWorksheet($objPHPExcel->getActiveSheet()); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); Quote Link to comment https://forums.phpfreaks.com/topic/261361-write-image-in-excel-file-using-php/#findComment-1339776 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.