thomasw_lrd Posted February 23, 2012 Share Posted February 23, 2012 I'm using PHPExcel to output an excel file. My problem is that it is printing the data backwards. ID Priority 1 low 2 high 3 low But when it prints to excel via this function // output data rows if (isset($apptable['retarr']) && isset($apptable['retarr']['rs']) && count($apptable['retarr']['rs'])>0){ foreach ($apptable['retarr']['rs'] as $row=>$r){ if (is_numeric($row)){ //echo '<pre>'.print_r($r, true).'</pre>';exit; $cols=0; foreach ($r as $col=>$c){ if (isset($colarr[$col])){ //echo '<pre>'.print_r($r, true).'</pre>';exit; $objPHPExcel->getActiveSheet()->SetCellValue($xlcols[$cols].$rows, $r[$col]); $objPHPExcel->getActiveSheet()->getStyle($xlcols[$cols].$rows, $r[$col])->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT); $cols++; } } $rows++; } It prints the data in reverse order ID Priority low 1 high 2 low 3 I've tried several troubleshooting techniques. When I echo out $r[$col] from this line I get the right data backwards. It prints low 1 high 2 low 3 in the first cell of my excel sheet. $objPHPExcel->getActiveSheet()->SetCellValue($xlcols[$cols].$rows, $r[$col]); I've tried not resetting $cols=0 and using $cols-- but I get an undefined . This leads me to believe that one of my foreach statements is wrong, but I'm not sure how to get anything useful out of them to see where it might be wrong. I've tried several echo "<pre>"; print_r(*); echo "</pre>"; statements where * is various array variables in my foreach statement. Any ideas on how to fix it? Or what I should try printing to the screen to see which statement is wrong? Quote Link to comment https://forums.phpfreaks.com/topic/257643-phpexcel/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.