Jump to content

Write Image in Excel file using PHP


komal

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/261361-write-image-in-excel-file-using-php/
Share on other sites

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();

?>

 

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__));

Hello darkfreaks,

 

Thank you for youre help! Yes, this code works perfect!!!

 

Thanks a lot.  :D

 

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__));

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.