1

I want to execute this sum formula, but I am filling the cells with columns and rows, how can I get the name of the last column to place it in the range

$sheet->setCellValueByColumnAndRow($col, $row, $score);
$sheet->setCellValueByColumnAndRow(($col + 1), $row, "=SUM(E{$row}:{$col_name}{$row})");
$sheet->getCellByColumnAndRow(($col + 1), $row)->getCalculatedValue();

I tried

$sheet->setCellValueByColumnAndRow($col, $row, "=SUM(E{$row}:{$sheet->getCellByColumnAndRow($col, $row)})");
  • Does this answer your question? [PHPExcel how to get column index from cell](https://stackoverflow.com/questions/3458978/phpexcel-how-to-get-column-index-from-cell) – miken32 Mar 13 '23 at 19:42

1 Answers1

2

Not 100% certain I understand the requirement, but assuming my interpretation is correct, the Cell getCoordinate() method should hopefully do what you are looking for. Try this:

$sheet->setCellValueByColumnAndRow($col, $row, "=SUM(E{$row}:{$sheet->getCellByColumnAndRow($col, $row)->getCoordinate()})");
John Rix
  • 6,271
  • 5
  • 40
  • 46