php - PHPExcel more than one image in a cell -
i need create excel document 2 col. first 1 contain multiple images 150px large , seconde 1 contain web code. reason 1 image added , file appears currupted. not sure doing wrong ...
<?php include("../../init.php"); if (is_numeric($_get[groupe])){ define( 'pclzip_temporary_dir', $_config['upload']['root'].'/cache' ); // filename download $groupe = mysql_query("select * photographe_groupe 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 * photographe_images sid='$_get[groupe]' group `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 * photographe_images 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 , output demo here
just few points note before try taking @ file:
the first point note here excel doesn't store images in cells, "overlays" images, , doesn't particularly care cell boundaries occur, image can fixed size irrespective of how many cells overlays
when specify coordinate image, you're relating top-left corner of image placed @ top-left corner of cell.... bottom and/or right corner of image lies isn't determined cells @ all. setting row height or column width autosize not affected image in way, because image overlaid, not content of cell
you can, offset image top-left corner of related cell using drawing object's setoffsetx()
, setoffsety()
methods.
you can link more 1 image placed relative same cell's top-left corner using different offset values don't overlap, need work out offsets size of images
Comments
Post a Comment