2013-02-28 77 views
1

我會搜索谷歌,但我找不到這方面的任何解決方案。
我想要做的是從一個報告使用PHP製作excel5導出文件。PHPExcel致命錯誤:未捕獲的異常「異常」有消息「公式錯誤:意外,」

每當我試圖做一個平均的時候,我發現了以下錯誤:

Fatal error: Uncaught exception 'Exception' with message 'myexcelsheet!F38 -> Formula Error: Unexpected ,' 

這是給出了錯誤的公式:

=SUM(F9:F36)/COUNTIF(F9:F36, "*" & "<>00:00:00" & "*") 

細胞的數據類型是時間。使用COUNT它可以正常工作,但它需要忽略00:00:00時間。

這是包括:

require_once("PHPExcel/Classes/PHPExcel.php"); 
require_once("PHPExcel/Classes/PHPExcel/Writer/Excel5.php"); 
require_once 'PHPExcel/Classes/PHPExcel/Cell/AdvancedValueBinder.php'; 

所有錯誤:

Fatal error: Uncaught exception 'Exception' with message 'myexcelsheet!F38 -> Formula Error: Unexpected ,' in /path/to/PHPExcel/Classes/PHPExcel/Cell.php:293 Stack trace: #0 /path/to/PHPExcel/Classes/PHPExcel/Worksheet.php(702): PHPExcel_Cell->getCalculatedValue() #1 /path/to/PHPExcel/Classes/PHPExcel/Writer/Excel5/Worksheet.php(295): PHPExcel_Worksheet->calculateColumnWidths() #2 /path/to/PHPExcel/Classes/PHPExcel/Writer/Excel5.php(194): PHPExcel_Writer_Excel5_Worksheet->close() #3 /path/to/rep-functions.php(985): PHPExcel_Writer_Excel5->save('/path/t...') #4 /path/to/report.php(462): export_excel(Array, Array, 'report.ph...', Array, Array, Array) #5 {main} thrown in /path/to/PHPExcel/Classes/PHPExcel/Cell.php on line 293 

這是我從testFormula功能得到

 
Formula Value is=SUM(F9:F36)/COUNTIF(F9:F36,"*" & "00:00:00" & "*") 
Expected Value is UNKNOWN 
Parser Stack :- 

Array 
(
    [0] => Array 
     (
      [type] => Cell Reference 
      [value] => F9 
      [reference] => F9 
     ) 

    [1] => Array 
     (
      [type] => Cell Reference 
      [value] => F36 
      [reference] => F36 
     ) 
    [2] => Array 
     (
      [type] => Binary Operator 
      [value] => : 
      [reference] => 
     ) 

    [3] => Array 
     (
      [type] => Operand Count for Function SUM() 
      [value] => 1 
      [reference] => 
     ) 

    [4] => Array 
     (
      [type] => Function 
      [value] => SUM(
      [reference] => 
     ) 

    [5] => Array 
     (
      [type] => Cell Reference 
      [value] => F9 
      [reference] => F9 
     ) 

    [6] => Array 
     (
      [type] => Cell Reference 
      [value] => F36 
      [reference] => F36 
     ) 

    [7] => Array 
     (
      [type] => Binary Operator 
      [value] => : 
      [reference] => 
     ) 

    [8] => Array 
     (
      [type] => Value 
      [value] => "*" 
      [reference] => 
     ) 

    [9] => Array 
     (
      [type] => Value 
      [value] => "00:00:00" 
      [reference] => 
     ) 

    [10] => Array 
     (
      [type] => Binary Operator 
      [value] => & 
      [reference] => 
     ) 

    [11] => Array 
     (
      [type] => Value 
      [value] => "*" 
      [reference] => 
     ) 

    [12] => Array 
     (
      [type] => Binary Operator 
      [value] => & 
      [reference] => 
     ) 

    [13] => Array 
     (
      [type] => Operand Count for Function COUNTIF() 
      [value] => 2 
      [reference] => 
     ) 

    [14] => Array 
     (
      [type] => Function 
      [value] => COUNTIF(
      [reference] => 
     ) 

    [15] => Array 
     (
      [type] => Binary Operator 
      [value] =>/
      [reference] => 
     ) 

) 
CALCULATION ENGINE ERROR: Worksheet!F38 -> Formula Error: Unexpected , 
Evaluation Log: 
Array  
( 
) 

讓我知道如果你需要了解更多信息。

在此先感謝!

回答

4

使用此功能調試計算引擎:

function testFormula($sheet,$cell) { 
    $formulaValue = $sheet->getCell($cell)->getValue(); 
    echo 'Formula Value is' , $formulaValue , PHP_EOL; 
    $expectedValue = $sheet->getCell($cell)->getOldCalculatedValue(); 
    echo 'Expected Value is ' , ((!is_null($expectedValue)) ? $expectedValue : 'UNKNOWN') , PHP_EOL; 


    PHPExcel_Calculation::getInstance()->writeDebugLog = true; 
    $calculate = false; 
    try { 
     $tokens = PHPExcel_Calculation::getInstance()->parseFormula($formulaValue,$sheet->getCell($cell)); 
     echo 'Parser Stack :-' , PHP_EOL; 
     print_r($tokens); 
     echo PHP_EOL; 
     $calculate = true; 
    } catch (Exception $e) { 
     echo 'PARSER ERROR: ' , $e->getMessage() , PHP_EOL; 

     echo 'Parser Stack :-' , PHP_EOL; 
     print_r($tokens); 
     echo PHP_EOL; 
    } 

    if ($calculate) { 
     try { 
      $cellValue = $sheet->getCell($cell)->getCalculatedValue(); 
      echo 'Calculated Value is ' , $cellValue , PHP_EOL; 

      echo 'Evaluation Log:' , PHP_EOL; 
      print_r(PHPExcel_Calculation::getInstance()->debugLog); 
      echo PHP_EOL; 
     } catch (Exception $e) { 
      echo 'CALCULATION ENGINE ERROR: ' , $e->getMessage() , PHP_EOL; 

      echo 'Evaluation Log:' , PHP_EOL; 
      print_r(PHPExcel_Calculation::getInstance()->debugLog); 
      echo PHP_EOL; 
     } 
    } 
} 

您需要將工作表對象和小區ID作爲參數,它產生的詞法和語法分析器如何評估公式

詳細的日誌
+0

我已經添加了該功能,但是我無法從中做出某些功能。 – 2013-02-28 09:27:31

+0

輸出是在問題中。 – 2013-02-28 09:31:58

+0

SOrry,在功能中錯過了一條線 – 2013-02-28 09:35:09

相關問題