How to insert an image, Report title and Headers into an excel worksheet using PHP XLSX Writer?

489 views Asked by At

Sample Report Header I want to achieve

I want to achieve a report header like this. If I add Report Title and subtitle using $writer->writeSheetRow() then $writer->writeSheetHeader() doesn't display header row. Also, I cannot insert an image into the sheet. If there is any sample code, it will be really helpful. Thanks in advance!

 

1

There are 1 answers

1
AudioBubble On

Add the following codes before you generate the Excel:

//locate where you have saved your image
$image = imagecreatefromjpeg('images/officelogo.jpg');
$objDrawing = new PHPExcel_Worksheet_MemoryDrawing();
$objDrawing->setName('Sample image');$objDrawing->setDescription('Sample image');
$objDrawing->setImageResource($image);
$objDrawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG);
$objDrawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT);
$objDrawing->setHeight(150);
//Then locate where shall the image be placed in the excel, it indicates the UPPER LEFT corner if the image
$objDrawing->setCoordinates('A3');
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());