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表格的数据强制转为字符串,问题就解决了

马克一下

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值