0

Hello,
Recently I am using phpexcel and afer many tries I wasn't able to find out how to
make a document with a image in its header.
Here is a simplified code that I am using. Can someone helps me with this issue?!

<?php
require_once 'PHPExcel.php';
$objPHPExcel = new PHPExcel();
$objDrawing = new PHPExcel_Worksheet_HeaderFooterDrawing();
$objDrawing->setPath('header.jpg');
$objPHPExcel->getActiveSheet()->getHeaderFooter()->addImage($objDrawing, PHPExcel_Worksheet_HeaderFooter::IMAGE_HEADER_RIGHT);
$objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader("&C&G");
$objPHPExcel->setActiveSheetIndex(0)->setCellValueExplicit('A1',  'CODICE PRATICA');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter      = new PHPExcel_Writer_Excel2007($objPHPExcel);
$objWriter->save('test.xlsx');
?>
2
Contributors
2
Replies
15
Views
2 Years
Discussion Span
Last Post by klaus.veliu
0
<?php
require_once 'PHPExcel-1.7.7/Classes/PHPExcel.php';
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setCreator("Mangel Murti");
$objPHPExcel->getProperties()->setLastModifiedBy("Mangel Murti");
$objPHPExcel->getProperties()->setTitle("Testing");
$objPHPExcel->getProperties()->setSubject("Testiin Me");
$objPHPExcel->getProperties()->setDescription("what to see what to get.");

$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->SetCellValue('A1', 'Hello');
$objPHPExcel->getActiveSheet()->SetCellValue('B2', 'world!');
$objPHPExcel->getActiveSheet()->SetCellValue('D2', 'world!');
$objPHPExcel->getActiveSheet()->setTitle('MyTest');

$gdImage = imagecreatefromjpeg('header.jpg');
$objDrawing = new PHPExcel_Worksheet_MemoryDrawing();
$objDrawing->setName('Sample image');
$objDrawing->setDescription('TEST');
$objDrawing->setImageResource($gdImage);
$objDrawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG);
$objDrawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT);
$objDrawing->setHeight(100);
$objDrawing->setCoordinates('A1');
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('test.xlsx');

?>
0

Thank you Mangel,
I solved my problem with a tricky procedure.
Before adding the excel content I use phpexel load,
to load a template created in MS Office that has the header image as I wanted,
after inserting the rows inside the loaded template I save it where I wanted to :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.