Question

I'm Trying to divide value in cell 'A2 to A13' by 'B2 to B13' respectively.

require_once 'phpexcel/Classes/PHPExcel.php';

$objPHPExcel = new PHPExcel();
$F=$objPHPExcel->getActiveSheet();
$Line=2;

while($Trs=mysql_fetch_assoc($rs)){
    $F->setCellValue('H2','{=(A'.($Line).' / B'.($Line).')}')
      ->setCellValue('I'.$Line,'{=A2:A13/B2:B13}');
    ++$Line;
}

I have tried two ways to get the desired result

1: setCellValue('H2','{=(A'.($Line).' / B'.($Line).')}')

2: setCellValue('I'.$Line,'{=A2:A13/B2:B13}')

But none of these are working as desired:

Output 1: {=(A13 / B13)}

Output 2: {=A2:A13/B2:B13}

By desired Output I mean if value of A2 = 10 and B2 = 5 Then H2 and I2 should result in displaying '2' and not the formula used to get '2' as result.

Example xls file

From H2 to H13 is what I actually need.

Can anyone tell me what's the correct way to get the desired output? Am I missing any library file that needs to be included on the page?

Was it helpful?

Solution

Array formulae aren't supported in PHPExcel; but I don't understand why you're trying to set this as an array formula in the first place (at least for H2)

For H2

$F->setCellValue('H2','=A' . $Line . ' / B' . $Line);

But you realise that you're simply overwriting this with a different value in each iteration of your loop

But I don't know what you expect to see for the cells in column I

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top