PHPExcel - Export Missing Row -
can tell me wrong code exports headers ok missing 1 record export. many thanks
$rownumber = 1; //start in cell 1 while ($row = mysql_fetch_assoc($result)) { $col = 'a'; // start @ column // returns title row if ( $rownumber == 1 ){ $headers = array_keys($row); foreach($headers $header) { $objphpexcel->getactivesheet()->setcellvalue($col.$rownumber,$header); $col++; } $rownumber++; }else{ //returns content rows $col = 'a'; $rownumber foreach($row $cell) { $objphpexcel->getactivesheet()->setcellvalue($col.$rownumber,$cell); $col++; } $rownumber++; } } $objphpexcel->getactivesheet()->removecolumn('a',3);
you're displaying headers first row retrieved database, not data row....
$rownumber = 1; //start in cell 1 while ($row = mysql_fetch_assoc($result)) { $col = 'a'; // start @ column // returns title row if ( $rownumber == 1 ){ $headers = array_keys($row); foreach($headers $header) { $objphpexcel->getactivesheet()->setcellvalue($col.$rownumber,$header); $col++; } $rownumber++; } $col = 'a'; foreach($row $cell) { $objphpexcel->getactivesheet()->setcellvalue($col.$rownumber,$cell); $col++; } $rownumber++; } $objphpexcel->getactivesheet()->removecolumn('a',3);
Comments
Post a Comment