PHPExcel - Error Cyclic Reference in Formula

前端 未结 2 1809
星月不相逢
星月不相逢 2020-12-12 02:02

I keep reciving this error \"Cyclic Reference in Formula\".

When I am trying to download my excel file.

Now when im deleting the \'=\' from formula\'s from m

相关标签:
2条回答
  • 2020-12-12 02:37

    for me this occured when I specified a column range that was backwards. so instead of E10:E11 it was giving E11:E10 once I put it in lower to higher order the error went away. I was using a =SUM() function and I guess phpExcel and excel can't handle it backwards......

    0 讨论(0)
  • 2020-12-12 02:57

    A cyclic formula is one like (for example) cell A1 contains the formula =B1+1 while cell B1 contains =A1+1, ie. where executing the formula results in a chain of calculations that loops back on itself.

    This can be valid in Excel, though the default behaviour is to generate an error message when it is encountered. However, you can change this behaviour so that Excel will process the formula through a specified number of cycles or iterations.

    PHPExcel supports both behaviours: the default is to generate the error message, as Excel does. But if you set the calculations engine's $cyclicFormulaCount property to a value greater than 0, it will emulate the second behaviour that Excel can exhibit. At its simplest level:

    PHPExcel_Calculation::getInstance()->cyclicFormulaCount = 1;
    

    will suppress cyclic errors and allow a basic cyclic calculation to be executed, setting $cyclicFormulaCount to higher values will allow the formulae to be calculated through several cycles or iterations (to the value that you specify).

    The getOldCalculatedValue() method retrieves the result of a calculation as last executed by MS Excel itself. This may be correct, but is not guaranteed (eg: if formula calculation has been suppressed in Excel itself).

    Alternatively, you can prevent PHPExcel from calculating formulas before saving the file:

    $objWriter->setPreCalculateFormulas(FALSE);
    

    EDIT

    Since version 1.7.9 the Calculation engine has been modified so that there is one calculation engine instance for each workbook file, so it is necessary to indicate which instance you need to set the cyclicFormulaCount for.

    Rather than

    PHPExcel_Calculation::getInstance()->cyclicFormulaCount = 1;
    

    you would use

    PHPExcel_Calculation::getInstance($objPHPExcel)->cyclicFormulaCount = 1;
    
    0 讨论(0)
提交回复
热议问题