I am using the following code to copy rows in PHPSpreadsheet. However I would like to change the formula references in the copied rows to reflect the new row number. (e.g. (A1-B1), (A2-B2), A3-B3 etc.) Any suggestions?
function copyRowFull(&$ws_from, &$ws_to, $row_from, $row_to) {
$ws_to->getRowDimension($row_to)->setRowHeight($ws_from->getRowDimension($row_from)->getRowHeight());
$lastColumn = $ws_from->getHighestColumn();
++$lastColumn;
for ($c = 'A'; $c != $lastColumn; ++$c) {
$cell_from = $ws_from->getCell($c.$row_from);
$cell_to = $ws_to->getCell($c.$row_to);
$cell_to->setXfIndex($cell_from->getXfIndex());
$cell_to->setValue($cell_from->getValue());
}
}
You should be able to use the
updateFormulaReferences()
method of thePHPExcel_ReferenceHelper
class to update cell references in a formula string