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

?>

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.