Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

calculating sum with PHPExcel

Tags:

php

sum

phpexcel

I am new with PHPExcel and I need your help- I have problem with setCellValue in PHPExcel when calculating the sum. It gives me always 0.

Here is my code:

$objPHPExcel = PHPExcel_IOFactory::load("test.xls");

$row = 5; 
$S = $objPHPExcel->getActiveSheet();
while($row_data = mysql_fetch_array($result)){


$S->setCellValueExplicit('B'.$row, $row_data['cn']);
$S->setCellValueExplicit('C'.$row, $row_data['ld']);
$S->setCellValueExplicit('D'.$row, $row_data['cust_notify']);
$S->setCellValueExplicit('E'.$row, $row_data['code']);
$S->setCellValueExplicit('F'.$row, $row_data['company_name']);
$S->setCellValueExplicit('G'.$row, $row_data['rs']);
$S->setCellValueExplicit('H'.$row, $row_data['status']);
$S->setCellValueExplicit('I'.$row, $row_data['sueend']);
$S->setCellValueExplicit('J'.$row, $row_data['vclaimed']);
$S->setCellValueExplicit('K'.$row, $row_data['ref']);
$S->setCellValueExplicit('M'.$row, $row_data['out']);

$row++;

$S->setCellValue("I$row", "Total");
$S->setCellValue("J$row", "=SUM(J5:J".($row-1).")");

}

The result I get is always "0". Bellow the print screen RESULT EXCEL

I would really appreciate if someone can help me with this issue.

Thanks in advance

like image 639
Lilou Avatar asked Apr 08 '13 09:04

Lilou


1 Answers

try this

$writer = PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
$writer->setPreCalculateFormulas(true);
like image 105
AlumnoPower Avatar answered Sep 30 '22 01:09

AlumnoPower