How to automatically read in calculated values with PHPExcel?

前端 未结 5 1945
广开言路
广开言路 2020-12-05 06:15

I have the following Excel file:

\"alt

I read it in by looping

相关标签:
5条回答
  • 2020-12-05 06:55

    getCalculatedValue() seems to do the right job you wanted. It will return the correct value if the cell contains FBV ( formula based value ). If not then the normal value will be returned instead.

    0 讨论(0)
  • 2020-12-05 06:57

    If you are unsure about the content of a cell (value or formula included), I recommend you to primarily do a check if the cell has a formula and then copy - paste accordingly. getOldCalculatedValue() is very helpful in this case. Here is an example of that:

    $code = $sheet->getCell('A'.$y)->getValue();
    if(strstr($code,'=')==true)
    {
        $code = $sheet->getCell('A'.$y)->getOldCalculatedValue();
    }
    $objPHPExcel4->setActiveSheetIndex(0)
                 ->setCellValue('A'.$l, $code);
    

    For large data sets, getCalculatedValue() function is really cumbersome and lots of memory will be required to perform correctly.

    0 讨论(0)
  • 2020-12-05 07:08

    getCalculatedValue() seems to work for all cells, see above

    0 讨论(0)
  • 2020-12-05 07:11

    I have never imported an excel file in PHP so this is just a stab in the dark.

    Why not check the first character in the cell for an "="

    If true getCalculatedValue()
    if not getCell()

    0 讨论(0)
  • 2020-12-05 07:18

    Looks like getCalculatedValue() is deprecated. Try using getFormattedValue() instead.

    0 讨论(0)
提交回复
热议问题