I have checked many sites for solution of my problem but not found proper solution. I want to insert formula which will calculate the total of marks obtained by students. Ma
@Mark Baker Thank you for show the way I tried and done like this -
$calculatRow='';
for($ctr=0;$ctr < count($marksColumnArr);$ctr++)
{
$calculatRow.='(($'.$marksColumnArr[$ctr].'##/$'.$maXmarksColumnArr[$ctr].'$##)*'.$divisionVal[$ctr].')+';
}
$calculateArrbyRow=substr($calculatRow,0,-1);
// Replicate formula by row
for($j=5;$j<count($totalStudents)+5;$j++){
$formula=str_replace('##',$j,$calculateArrbyRow);
$cell=PHPExcel_Cell::stringFromColumnIndex($coumnStart+12);
$objPHPExcel->getActiveSheet()->setCellValue($cell.$j, '='.$formula);
}
$coumnStart=($coumnStart-1)+13; $subjectCtr++;
}
Read section 4.6.4 of the developer documentation, and examples like 03formulas.php
.
You can write a formula as you'd write it in Excel itself, simply store the formula prefixed with =
in the cell
e.g.
$objPHPExcel->getActiveSheet()
->setCellValue(
'E10',
'=SUM(A10:E9)'
);
Will write the formula =SUM(A10:E9)
in cell E10
When writing a formula to a cell, remember that:
.
(period),
(comma);
(semicolon)EDIT
for ($row = 1; $row <= 10; $row++) {
$objPHPExcel->getActiveSheet()
->setCellValue(
'J' . $row,
'=SUM(A'.$row.':C'.$row.')/10 + SUM(D'.$row.':F'.$row.')/20 + SUM(G'.$row.':I'.$row.')/60'
);
}