簡體   English   中英

PHPExcel-致命錯誤:帶有消息的未捕獲異常“ Exception”

[英]PHPExcel - Fatal error: Uncaught exception 'Exception' with message

每次嘗試導出Excel電子表格時,都會出現錯誤。 錯誤如下:

Fatal error: Uncaught exception 'Exception' with message 'Worksheet!J6 -> Worksheet!J6 -> Cyclic Reference in Formula' in /classes/PHPExcel/Cell.php:293 Stack trace: 
    #0 /classes/PHPExcel/Writer/Excel2007/Worksheet.php(997): PHPExcel_Cell->getCalculatedValue() 
    #1 /classes/PHPExcel/Writer/Excel2007/Worksheet.php(943): PHPExcel_Writer_Excel2007_Worksheet->_writeCell(Object(PHPExcel_Shared_XMLWriter), Object(PHPExcel_Worksheet), 'J6', Array, Array) 
    #2 /classes/PHPExcel/Writer/Excel2007/Worksheet.php(83): PHPExcel_Writer_Excel2007_Worksheet->_writeSheetData(Object(PHPExcel_Shared_XMLWriter), Object(PHPExcel_Worksheet), Array) 
    #3 /classes/PHPExcel/Writer/Excel2007.php(282): PHPExcel_Writer_Excel2007_Worksheet->writeWorksheet(Object(PHPExcel_Worksheet), Array, false) 
    #4 /includes/reports_funcs.php(620): PHPExcel_Writer_Excel2007->save('reports/risk-bo...') #5 /createXlsxReport. in /classes/PHPExcel/Cell.php on line 293

我試圖尋找解決方案,但到目前為止還沒有運氣。 我發現了另一個stackoverflow問題,建議添加$objWriter->setPreCalculateFormulas(FALSE); 在保存文件之前,但這給了我一個空的電子表格。

它只是在最近才開始發生,所以我對於為什么會發生感到非常困惑。 任何幫助將不勝感激,歡呼

樣本代碼-編輯

$objPHPExcel->getActiveSheet(0)
    ->setCellValueByColumnAndRow(0, $row, $pol_ref . 'e' . $end_numb)
    ->setCellValueByColumnAndRow(1, $row, $insured_name)
    ->setCellValueByColumnAndRow(2, $row, $vessel_name)
    ->setCellValueByColumnAndRow(3, $row, $insurance_type . ' - ' . $end_type)
    ->setCellValueByColumnAndRow(4, $row, $insured_domicile)
    ->setCellValueByColumnAndRow(5, $row, gmdate("d-m-Y",$date_logged))
    ->setCellValueByColumnAndRow(6, $row, $inception_date)
    ->setCellValueByColumnAndRow(7, $row, $expiry_date)
    ->setCellValueByColumnAndRow(8, $row, ($policy_limit == 0.00?$loh_limit:$policy_limit))
    ->setCellValueByColumnAndRow(9, $row, $premium)
    ->setCellValueByColumnAndRow(10, $row, "=sum(J".($row)."*".($seacurus_percent/100).")")
    ->setCellValueByColumnAndRow(11, $row, "=sum(J".($row)."*".($placing_percent/100).")")
    ->setCellValueByColumnAndRow(12, $row, "=sum(J".($row)."*".($rebate_percent/100).")")
    ->setCellValueByColumnAndRow(13, $row, "=sum(J".($row)."*".($iptpercent/100).")")
    ->setCellValueByColumnAndRow(14, $row, "=sum(".($binder_id==6?"(J".$row." - (P".$row."+L".$row."+O".$row."+P".$row."))":"J".($row))."*".$bgn_percent.")")
    ->setCellValueByColumnAndRow(15, $row, "=sum(J".($row)."*".$ghc_percent.")")
    ->setCellValueByColumnAndRow(16, $row, "=sum(J".($row)."*".($commission_percentage_sum/100).")");
$row++;

如果您的公式包含循環引用,那么您需要選擇處理方式,就像在MS Excel本身中一樣。 默認行為是拋出這樣的異常,這類似於MS Excel默認情況下的行為。 另一種方法是通過將計算引擎設置為以下命令,告訴PHPExcel按照固定的迭代次數進行循環:

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

或大於= 1的任何值,表示要循環的迭代次數

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

// 10次迭代

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM