PHP Fatal error: Uncaught exception 'PHPExcel_Calculation_Exception'(PHPExcel 数据问题)

最近遇到的一个bug,根据条件搜索出来的数据,用PHPExcel导出Excel,很奇葩的问题是:只有某一天的数据导出来报错:找不到文件...

百思不得其解,各个步骤数据都获取到了,可以打印出来,没有毛病,后来用fiddler监听,发现报了一个500的错误:PHP Fatal error: Uncaught exception 'PHPExcel_Calculation_Exception' ...

查了一波,大多是说导出的数据中有特殊符号 “=” 导致Excel把等号后面的当成公式处理,所以出错

可是,问题是数据太大,这个“=”也不好找

在stack overflow上找到了答案:引用一下

I'm guessing that one of the values retrieved from your database begins with an = sign, in which case PHPExcel will "guess" that it's supposed to be a formula and store it as such.

If you have values that begin with an = that aren't formulae, then you need to tell PHPExcel that it is a string and that it should be stored as such.

This behaviour is defined in the default cell binder (PHPExcel/Cell/DefaultValueBinder.php).

If you want to force PHPExcel to store these values as strings, then you can use the setCellValueExplicit() method (which defaults to enforcing a string)

Or you can write a custom value binder and apply that instead of the default value binder

setCellValueExplicit()把所有的输出到Excel表格的数据强制转为字符串,问题就解决了

马克一下

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章