robins robins - 5 months ago 18
PHP Question

setCellValue in phpExcel

I want to export a report to excel.Now its little okey.I'm stuck in setCellValue.
Take all the values using loop.In final,after looping i want a Sum row.That is the sum of all columns.

Code

$row = 2;
$no = 1;
foreach($p_det as $n){
$objPHPExcel->getActiveSheet()->setCellValue('A'.$row,$no);
$objPHPExcel->getActiveSheet()->setCellValue('B'.$row,$n->student_id);
$objPHPExcel->getActiveSheet()->setCellValue('C'.$row,$n->reg_fee);

$row++;
$no++;
}

$objPHPExcel->getActiveSheet()->setCellValue('A'.$row+1,'SUM');


i add this last line my export is not working

Please help me

Answer

Rewrite the line

$objPHPExcel->getActiveSheet()->setCellValue('A'.$row+1,'SUM');

With the below one

$objPHPExcel->getActiveSheet()->setCellValue('A'.($row+1),'SUM');

It will work

With the (), it will clearly extract the single numeric value. With out the parenthesis, it may make issues.