PHPExcel: Set Column Names fromArray using PHP array -
i'm using phpexcel library export data excel. i'm able data excel expected. how can set column names php array. here code i'm using. please help
$data=( array(10) ( [0] => array(8) ( [#] => (string) [name] => (string) student1 [id] => (string) 123456 [date] => (string) 2016-02-01 [group] => (string) physics [month] => (string) february [year] => (string) 2016 ) [1] => array(8) ( [#] => (string) [name] => (string) student2 [id] => (string) 569874 [date] => (string) 2016-02-01 [group] => (string) biology [month] => (string) february [year] => (string) 2016......); $objphpexcel = new phpexcel(); $objphpexcel->setactivesheetindex(0); $objphpexcel->getactivesheet()->setcellvalue('a1', "#"); $objphpexcel->getactivesheet()->setcellvalue('b1', "name"); $objphpexcel->getactivesheet()->setcellvalue('c1', "id"); $objphpexcel->getactivesheet()->setcellvalue('d1', "date"); $objphpexcel->getactivesheet()->setcellvalue('e1', "group"); $objphpexcel->getactivesheet()->setcellvalue('f1', "month"); $objphpexcel->getactivesheet()->setcellvalue('g1', "year");
//how replace/make dynamic lines above set cell values in first row based on array data column names. i.e name, id, date,.....
//add data $objphpexcel->getactivesheet()->fromarray($data,null,'a2');
like ?
$objphpexcel->getactivesheet()->fromarray(array_keys($data[0]),null,'a2');
now know that's want do, short explain.
array_keys copy's keys array value numbered array, if have array this:
[#] => (string) [name] => (string) student1 [id] => (string) 123456 [date] => (string) 2016-02-01 [group] => (string) physics [month] => (string) february [year] => (string) 2016
it return following array:
[0] = "#" [1] = "name" [2] = "id" ...
Comments
Post a Comment