1. 程式人生 > >php 匯出 Excel 報錯 exception 'PHPExcel_Calculation_Exception' with message

php 匯出 Excel 報錯 exception 'PHPExcel_Calculation_Exception' with message

exception 'PHPExcel_Calculation_Exception' with message '粉絲資料!C2679 -> Formula Error: Operator '=' has no operands' in D:\www\czydweixin\Extend\Vendor\PHPExcel\PHPExcel\Cell.php:300 Stack trace: #0 D:\www\czydweixin\Extend\Vendor\PHPExcel\PHPExcel\Writer\Excel5\Worksheet.php(460): PHPExcel_Cell->getCalculatedValue() #1 D:\www\czydweixin\Extend\Vendor\PHPExcel\PHPExcel\Writer\Excel5.php(187): PHPExcel_Writer_Excel5_Worksheet->close() #2 D:\www\czydweixin\PigCms\Lib\Action\User\Wechat_groupAction.class.php(294): PHPExcel_Writer_Excel5->save('php://output') #3 [internal function]: Wechat_groupAction->index() #4 D:\www\czydweixin\Lib\Core\App.class.php(183): ReflectionMethod->invoke(Object(Wechat_groupAction)) #5 D:\www\czydweixin\Lib\Core\App.class.php(219): App::exec() #6 D:\www\czydweixin\Lib\Core\Think.class.php(39): App::run() #7 D:\www\czydweixin\Common\runtime.php(243): Think::start() #8 D:\www\czydweixin\index.php(37): require('D:\www\czydweix...') #9 {main}

關鍵點:Error: Operator '=' has no operands'

導致問題原因可能是匯出欄位中包含有  ‘=’  ,解決辦法:在欄位前拼上一個半單引號。

 if(strpos($lists[$i-2]['nickname'],'=') === 0){
                $lists[$i-2]['nickname'] = "'".$lists[$i-2]['nickname'];
            }