robins
robins

Reputation: 1668

setCellValue in phpExcel

I want to export a report to Excel. Now it's little okay. I'm stuck in setCellValue. I want to 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.

Upvotes: 0

Views: 9270

Answers (1)

Arun
Arun

Reputation: 3731

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.

Upvotes: 2

Related Questions