Jump to content

Recommended Posts

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? 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/257643-phpexcel/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.