php - how to pass array value to excel -
i have array
array(4) { [0]=> string(2) "12" [1]=> string(2) "17" [2]=> string(2) "1.0" [3]=> string(2) "1.7" } array(4) { [0]=> string(1) "3" [1]=> string(1) "1" [2]=> string(2) "4.1" [3]=> string(2) "4.6" }
i need pass value excel(start column c) code
foreach ($rate $row) { $i = 0; $j = 2; foreach ($row $item) { $myxls->write_string($i, $j++, $row); } $i++; }
but why can wrote second array(3,1,4.1,4.6) in first line. first row missing. wrong in foreach ?
stating column c
$this->load->library('phpexcel/phpexcel'); $objphpexcel = new phpexcel; $objphpexcel->getdefaultstyle()->getfont()->setname('arial'); $objphpexcel->getdefaultstyle()->getfont()->setsize(11); $objwriter = phpexcel_iofactory::createwriter($objphpexcel, "excel2007"); $objsheet = $objphpexcel->getactivesheet(); $array = array( array('name' => 'myname1', 'email' => 'email1'), array('name' => 'myname2', 'email' => 'email2') ); $num=0; foreach($array $v) { $num++; $objsheet->getcell('c'.$num)->setvalue($v['name']); $objsheet->getcell('d'.$num)->setvalue($v['email']); } $objwriter->save("file.xlsx");
Comments
Post a Comment