I need to create an excel document with only 2 col. The first one will contain multiple images 150px large and the seconde one will contain a web code. For some reason only one image is added and the file appears to be currupted. Not sure what i am doing wrong ...
<?php
include("../../init.php");
if (is_numeric($_GET[groupe])){
define( 'PCLZIP_TEMPORARY_DIR', $_CONFIG['upload']['root'].'/cache' );
// filename for download
$groupe = mysql_query("SELECT * FROM photographe_groupe WHERE id='$_GET[groupe]'");
$records = "Groupe - $groupe[nom].xlsx";
header('Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition:inline;filename='.$records);
$workbook = new PHPExcel;
$sheet = $workbook->getActiveSheet();
$i=0;
$select = mysql_query("SELECT * FROM photographe_images WHERE sid='$_GET[groupe]' group by `paire`");
while($photo = mysql_fetch_array($select)){
// Table header
if ($i=="1"){
$sheet->setCellValue("A1",'Photo(s)');
$sheet->setCellValue('B1','Code Web');
$i++;
}
// Set images in col 1
$select1 = mysql_query("SELECT * FROM photographe_images WHERE paire='$photo[paire]'");
while($photo1 = mysql_fetch_array($select1)){
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName($photo1[img]);
$objDrawing->setDescription($photo1[img]);
$objDrawing->setWorksheet($workbook->getActiveSheet());
$objDrawing->setPath($_CONFIG['upload']['root'].'/userfiles/photos/'.$photo1[img]);
$objDrawing->setWidth(150);
$objDrawing->setCoordinates('A'.$i);
}
// Set web code in col 2
$sheet->setCellValue("B$i",$photo[code_web]);
$i++;
}
}
$workbook->getActiveSheet()->getRowDimension(1)->setRowHeight(-1);
$writer = new PHPExcel_Writer_Excel2007($workbook);
PHPExcel_Settings::setZipClass(PHPExcel_Settings::PCLZIP);
$writer->save('php://output');
?>
You can download and output demo here