Relative reference in phpexcel

Topics: User Forum
Jul 23, 2013 at 9:14 AM
Can i use relative reference in PHPexcel?
Coordinator
Jul 23, 2013 at 12:50 PM
In what way? In formulas? Can you explain what you mean?
Jul 23, 2013 at 3:48 PM
Yes. In formulas. I mean use formulas like "=list1!RC+list2!RC+list3!R[-1]C". I think such formulas in some cases wouldn't require updates using updateFormulaReferences() and insertNewBefore().
And i find a problem (i think) with updateFormulaReferences() and formulas containing reference on other sheet ( "=list!A1").
Coordinator
Jul 23, 2013 at 4:27 PM
R1C1 format isn't supported in the current version of the calculation engine; but it's something that I'm actively working on for version 2.0 of PHPExcel
Sep 4, 2014 at 7:35 AM
MarkBaker wrote:
R1C1 format isn't supported in the current version of the calculation engine; but it's something that I'm actively working on for version 2.0 of PHPExcel
It should be quite easy to implement on your own:
// Support for relative paths in preset formulas
                    $pattern = '/R\[([\-\+]?[0-9]*)\]C\[([\-\+]?[0-9]*)\]/';
                    $value = preg_replace_callback(
                        $pattern,
                        function($matches) use($rowIndex,$columnIndex){
                            $res = ( PHPExcel_Cell::stringFromColumnIndex($columnIndex+(int)$matches[2]) ).( $rowIndex+(int)$matches[1] );

                            return $res;
                        }
                        ,$value
                    );